Given an integer array nums of length n where all integers are in the range [1, n] and each integer appears once or twice, return an array of all integers that appear twice.
You must write an algorithm that runs in O(n) time and uses only O(1) extra space.
Example 1:
Input: nums = [4, 3, 2, 7, 8, 2, 3, 1]
Output: [3, 2]
Explanation: 3 and 2 each appear twice.
Example 2:
Input: nums = [1, 1, 2]
Output: [1]
Explanation: 1 appears twice.
Example 3:
Input: nums = [1]
Output: []
n == nums.length1 <= n <= 10^51 <= nums[i] <= n