Description
Given an integer array nums of length n where all integers are in [1, n] and each appears once or twice, return array of integers that appear twice.
Examples
Input:
nums = [4,3,2,7,8,2,3,1]Output:
[2,3]Explanation:
2 and 3 appear twice.
Input:
nums = [5,4,6,7,9,3,10,9,5,6]Output:
[5,6,9]Explanation:
The numbers 5, 6, and 9 each appear exactly twice in the array, while 4, 7, 3, and 10 appear only once.
Input:
nums = [1,2,3,4,5]Output:
[]Explanation:
No duplicates exist in this array - each number from 1 to 5 appears exactly once, so the result is an empty array.
Constraints
- •
1 ≤ n ≤ 10⁵