Find The Duplicate Number
An array of n+1 integers contains values 1..n, with exactly one value appearing multiple times. Return that value without modifying nums, using constant auxiliary space.
Example 1
nums = [2,1,4,3,2]2Explanation
2 occurs twice while the other values appear once.
Example 2
nums = [1,1]1Explanation
The smallest valid array repeats 1.
Example 3
nums = [3,3,3,3]3Explanation
3 is the one repeated value even though its multiplicity is four.
Constraints
- 2 <= len(nums) <= 100001
- One distinct value is repeated; its multiplicity may exceed two
Function contract
findDuplicateArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[2,1,4,3,2]