LeetCode - Algorithms - 448. Find All Numbers Disappeared in an Array

Problem

448. Find All Numbers Disappeared in an Array

Java

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
final int N = nums.length;
int[] arr = new int[N+1];
for(int i=0;i<nums.length;i++) {
arr[nums[i]]++;
}
List<Integer> list = new ArrayList<Integer>();
for(int i=1;i<arr.length;i++) {
if (arr[i]==0) {
list.add(i);
}
}
return list;
}
}

Submission Detail

  • 33 / 33 test cases passed.
  • Runtime: 6 ms, faster than 37.69% of Java online submissions for Find All Numbers Disappeared in an Array.
  • Memory Usage: 64 MB, less than 5.08% of Java online submissions for Find All Numbers Disappeared in an Array.