-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
448.java
44 lines (41 loc) · 1.33 KB
/
448.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> list = new ArrayList<>();
boolean[] b = new boolean[nums.length + 1];
for (int i = 0; i < nums.length ; i++) {
b[nums[i]] = true;
}
for (int i = 1; i < b.length; i++) {
if (!b[i]) {
list.add(i);
}
}
return list;
}
}
__________________________________________________________________________________________________
sample 46084 kb submission
class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> list = new ArrayList<>();
if(nums == null || nums.length == 0) {
return list;
}
int res = 0;
for(int i = 0; i < nums.length; i++) {
int index = Math.abs(nums[i]) - 1;
if(nums[index] > 0) {
nums[index] = -nums[index];
}
}
for(int i = 0; i < nums.length; i++) {
if(nums[i] > 0) {
list.add(i+1);
}
}
return list;
}
}
__________________________________________________________________________________________________