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 uses only constant extra space.
Test Cases
Input:
(int[]) nums = [1,3,4,2,2]
Output:
Input:
(int[]) nums = [3,1,3,4,2]
Output:
Solution
Time Complexity: O(n)
Space Complexity: O(1)