The array nums has length n. Each value is between 1 and n, and no value occurs more than twice. Return every value that occurs twice, listing each repeated value once. You may return the values in any order. Your algorithm should run in O(n) time and use O(1) auxiliary space, excluding the returned array. You may modify nums.
Example 1:
Input: nums = [3,1,3,2,2]
Output: [2,3]Explanation: Values 2 and 3 each appear twice, while 1 appears once. Return [2,3]; [3,2] is also valid.
Example 2:
Input: nums = [2,1,3]
Output: []Explanation: Every value appears exactly once, so there are no duplicates and the result is empty.
Example 3:
Input: nums = [1,1]
Output: [1]Explanation: The value 1 appears twice. Include it once in the returned array.
Constraints:
1 <= n <= 1000001 <= nums[i] <= n- Every value occurs at most twice.