You are given an integer array nums of length n where every element is in the range [1, n], and each integer appears either once or twice. Return an array of all the integers that appear twice. The returned array must be sorted in ascending order.
Input / output
nums: int[]int[] containing every value that appears exactly twice, sorted ascending1 <= nums.length <= 10^51 <= nums[i] <= nums.lengthnums appears either once or twiceCan you solve it in O(n) time and O(1) extra space (not counting the output array), for example by marking visited values in place with nums[abs(val) - 1] *= -1 and detecting when a position is already negative?