Description:
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
Solution:
Time Complexity : O(n)
Space Complexity: O(n)
var containsDuplicate = function(nums) {
const map = {}
for(const num of nums) {
// If we have seen this num before return true
if(map[num]) return true
map[num] = true
}
return false
};
Top comments (0)