Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and using only constant extra space.
Example 1
Input: nums = [1,3,4,2,2]
Output: 2
Explanation: The values 1-4 each appear once, except 2, which appears at indices 3 and 4. So the duplicate is 2.
Example 2
Input: nums = [3,1,3,4,2]
Output: 3
Explanation: 3 appears at indices 0 and 2. Every other value appears once.
Example 3
Input: nums = [1,1]
Output: 1
Explanation: With n = 1 the only allowed value is 1, and it appears twice.
Treat each value as a 'next' pointer: index i links to index nums[i]. Because some value repeats, two indices point to the same place, creating a cycle whose entrance is the duplicate.
Run checks all cases above. Submit evaluates all test cases.