217. Contains Duplicate

Solution

/**
 * @param {number[]} nums
 * @return {boolean}
 */
var containsDuplicate = function(nums) {
    const map = [];
    
    for(let n of nums) {
        if (!map[n]) {
            map[n] = 1;
        } else {
            return true;
        }
    }
    
    return false;
};

Complexity

  • Time Complexity: O(N), where N is the size of nums.
  • Space Complexity: O(N), where N is the size of map

All Solutions