Understanding Contains Duplicate
Return whether any integer appears more than once in nums.
How it works
A set records membership so each new value needs only one lookup.
Start with an empty set. Check whether each value has already appeared. Insert unseen values; return false if the scan finishes.
Try an example
Input: nums = [1, 2, 3, 1]
Output: true
A set records membership so each new value needs only one lookup.
Constraints
- 0–64 integers between -1,000,000 and 1,000,000.
- An empty array contains no duplicates.
Use the simulator
Change the input, then choose Visualize input. Use Next and Previous to inspect each decision, or Play to advance automatically. Compare approaches and their complexity. Choose Try yourself to write JavaScript, select My code and Visualize code to inspect its execution, or Run Tests to check results.
Execution happens in your browser. Drafts are saved locally; avoid entering secrets or sensitive information.