As i loop through the numbers i check if a number exists onthemap.if it does i return true if it doesnt i and add the number to the map and continue. if there are no duplicates false is returned.
-
Time complexity:O(N)
-
Space complexity:O(N)
function containsDuplicate(nums: number[]): boolean {
let map = new Map()
for (let i = 0; i < nums.length; i++) {
if (map.has(nums[i])) return true
map.set(nums[i], nums[i])
}
return false
};