2. Contains Duplicate

Return true if any value appears at least twice in nums, and false if every element is distinct.

Example 1

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

Example 2

Input: nums = [7,8,9]
Output: false

Constraints

  • 1 ≤ nums.length ≤ 10⁵
Hint 1

What data structure answers “have I seen this before?” in O(1)?

ArrayHash Table