In an array containing n + 1 integers where each integer is between 1 and n (inclusive), there is exactly one duplicate number. Find this duplicate number without modifying the array and using only constant extra space.
- An array of integers
nums.
- An integer representing the duplicate value.
- 1 <= n <= 10^5
- nums.length == n + 1
- 1 <= nums[i] <= n
- All the integers in
numsappear only once except for one integer which appears two or more times.
Input: nums = [1, 3, 4, 2, 2]
Output: 2
Explanation: 2 is the repeating integer.