#217 Contains Duplicate

EasyArrays & Hashing~10 min

Given an integer array nums, decide whether any value occurs more than once. Return true if at least one duplicate exists, false if every element is distinct.

Examples

Inputnums = [1, 2, 3, 1]
Outputtrue

The value 1 appears at index 0 and index 3.

Inputnums = [1, 2, 3, 4]
Outputfalse

All four values are distinct.

Constraints

  • 1 ≤ nums.length ≤ 10⁵
  • -10⁹ ≤ nums[i] ≤ 10⁹

The explainer is the good part.

Sign in for the full intuition build-up, every approach from naive to optimal with complexity analysis, progressive hints, and commented solutions in Python, JavaScript, and Java. All free.

Want a taste first? Try a free sample: Two Sum or Valid Parentheses.