Problem
You get an array nums of n + 1 integers. Each integer is in the range [1, n].
Exactly one value occurs more than one time in nums. That value can occur two or more times. Return that value.
Do not change nums, and use only O(1) extra memory.
Example 1
- Input:
- nums = [2,5,1,3,5,4]
- Output:
- 5
- Explanation:
- Here,
nis 5. The value 5 occurs two times.
Example 2
- Input:
- nums = [4,4,4,2,1]
- Output:
- 4
- Explanation:
- The value 4 occurs three times.
Constraints
- 1 <= n <= 10^5
- nums.length == n + 1
- 1 <= nums[i] <= n
- Exactly one integer in nums occurs two or more times. All the other integers occur one time only.
Follow-up
Find a solution that runs in O(n) time.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Find a credit card provider based on the credit card number
Coding
- Find and remove duplicate files
Coding · File & Media Storage · Operating Systems
- Find Closest Number to Zero
Coding
- Find Duplicate File in System
Coding · Array · Hash Table · String
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 287. Find the Duplicate Number
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source