Find All Duplicates In An Array
easy
1. Given an integer array nums of length n where all the integers of nums are in the range [1, n]. 2. Each integer appears once or twice, return an array of all the integers that appears twice. 3. You must write an algorithm that runs in O(n) time and uses only constant extra space.
Constraints
1. n == nums.length 2. 1 <= n <= 100000 3. 1 <= nums[i] <= n 4. Each element in nums appears once or twice.
Format
Input
Input is Managed for you 1. nums = [4,3,2,7,8,2,3,1] 2. nums = [1]
Output
Output is Managed for you 1. [2,3] 2. [], Empty
Example
Sample Input
8
4 3 2 7 8 2 3 1
Sample Output
2 3