Medium
Given an array nums of n+1 integers where each value is in [1, n], exactly one value is repeated. Return the repeated number without modifying the array and using O(1) extra space.
Input: nums = [1,3,4,2,2] Output: 2
Input: nums = [3,1,3,4,2] Output: 3