442. Find All Duplicates in an Array
Medium
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.
Example 1:
Example 2:
Example 3:
Constraints:
n == nums.length
1 <= n <= 105
1 <= nums[i] <= n
Each element in
nums
appears once or twice.
解題
使用陣列紀錄出現過的數字。
Last updated