Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.
You must write an algorithm that runs in O(n) time and uses only constant extra space.
I do not have any idea. constant space? still bit operations?
xor itself it must be zero. So all the element xor be 0? let me try.
the key point in the std is to find the relationship between nums[i] and nums[nums[i] - 1].
oh holy, std just let the element of the nums[nums[i] - 1] turn into negative. If the number is negative, it must have been used before, it means duplicates!
or if (nums[i] != nums[nums[i] - 1]){ swap(nums[i],nums[nums[i] - 1]); i--; }