- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo448.java
33 lines (29 loc) · 707 Bytes
/
No448.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
packageAlgorithm.leetcode.Array;
importjava.util.ArrayList;
importjava.util.HashSet;
importjava.util.List;
importjava.util.Set;
/**
*
* Created by tujietg on Nov 8, 2019
*/
publicclassNo448 {
publicstaticList<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> list = newArrayList<Integer>();
Set<Integer> hashSet = newHashSet<Integer>();
for (inti = 0; i < nums.length; i++) {
hashSet.add(nums[i]);
}
intn = nums.length;
for (inti = 1; i <= n; i++) {
if (!hashSet.contains(i)) {
list.add(i);
}
}
returnlist;
}
publicstaticvoidmain(String[] args) {
int[] param = newint[] { 4, 3, 2, 7, 8, 2, 3, 1 };
findDisappearedNumbers(param);
}
}