448 Find All Numbers Disappeared in an Array
1. Question
Input: [4,3,2,7,8,2,3,1]
Output: [5,6]2. Implementation
class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> res = new ArrayList<>();
if (nums == null || nums.length == 0) {
return res;
}
int n = nums.length;
int[] map = new int[n + 1];
for (int num : nums) {
++map[num];
}
for (int i = 1; i <= n; i++) {
if (map[i] == 0) {
res.add(i);
}
}
return res;
}
}3. Time & Space Complexity
Last updated