-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2215.java
More file actions
40 lines (32 loc) · 815 Bytes
/
Copy path2215.java
File metadata and controls
40 lines (32 loc) · 815 Bytes
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
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
class Solution {
public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
Set<Integer> inNums1 = new HashSet<>();
for (int n : nums1) {
inNums1.add(n);
}
Set<Integer> inNums2 = new HashSet<>();
for (int n : nums2) {
inNums2.add(n);
}
List<Integer> ret1 = new ArrayList<>();
for (int n : inNums1) {
if (!inNums2.contains(n)) {
ret1.add(n);
}
}
List<Integer> ret2 = new ArrayList<>();
for (int n : inNums2) {
if (!inNums1.contains(n)) {
ret2.add(n);
}
}
List<List<Integer>> ret = new ArrayList<>();
ret.add(ret1);
ret.add(ret2);
return ret;
}
}