#217 Contains Duplicate
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
Input
nums = [1, 2, 3, 1]Output
trueThe value 1 appears at index 0 and index 3.
Input
nums = [1, 2, 3, 4]Output
falseAll 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.