Contains Duplicate

EasyHash Maps and Sets

Given an integer array nums, return true if some value appears at least twice, and false if every element is distinct.

Only the values matter, not their positions: [5, 1, 5] has a duplicate even though the two 5s are not neighbours.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

Examples

Example 1

Input: nums = [1,2,3,1]
Output: true

1 appears at index 0 and index 3.

Example 2

Input: nums = [1,2,3,4]
Output: false

Every value is different.

Example 3

Input: nums = [4,4,4,4]
Output: true

Only one distinct value, repeated: the first repeat is found at index 1.

JavaScript you'll use: Map and Set Arrays: create, read, update

/**
 * @param {number[]} nums
 * @return {boolean}
 */
function containsDuplicate(nums) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.