š PracticeEasyAlgorithm ProblemCoding Ready
Contains Duplicate
arrayhash-table
LeetCode #217
Updated Dec 20, 2025
Question
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
LeetCode: Contains Duplicate
Example:
Input: nums = [1,2,3,1]
Output: true
Input: nums = [1,2,3,4]
Output: false
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true
Hints
Hint 1
Think about using a data structure that can track what you've seen so far. What has O(1) lookup time?
Hint 2
As you iterate through the array, check if each element is already in your set. If yes, you found a duplicate.
Hint 3
Alternatively, you could sort the array first and check adjacent elements. But is that more or less efficient?
Your Solution
python
Auto-saves every 30s
Try solving the problem first before viewing the solution
Learning Resources
0:00time spent