Given an array of n+1 integers where each integer is between 1 and n inclusive, return the duplicate number. Index placement or cycle detection both exploit the constrained value range.
nums = array containing one repeated value
the duplicate number
Example 1:
Input:
nums = [1,3,4,2,2]
Output:
2
Explanation:
The number 2 appears twice.
Example 2:
Input:
nums = [3,1,3,4,2]
Output:
3
Explanation:
The duplicate number is 3.