Contains Duplicate
Given an integer array nums, return true if any value appears at least twice in the array.
Return false if every element appears only once.
Example 1
Input
n = 4 nums = [1,2,3,1]
Output
true
Explanation
The value 1 appears twice.
Example 2
Input
n = 4 nums = [1,2,3,4]
Output
false
Explanation
Every element appears exactly once.
Constraints
Hints:
Hint 1
Use a set to keep track of the elements that have already appeared.
Hint 2
If an element is already present in the set, a duplicate exists. Otherwise, add the element to the set.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 19, 2026
Last updated
Aug 20, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output