-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDifferenceBetweenArrays.java
More file actions
44 lines (36 loc) · 1.43 KB
/
DifferenceBetweenArrays.java
File metadata and controls
44 lines (36 loc) · 1.43 KB
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
<<<<<<< HEAD
//2215. Find the Difference of Two Arrays
class Solution {
public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
for(int num : nums1) set1.add(num);
for(int num : nums2) set2.add(num);
List<Integer> list1 = new ArrayList<>();
List<Integer> list2 = new ArrayList<>();
for(int num : set1) if(!set2.contains(num)) list1.add(num);
for(int num : set2) if(!set1.contains(num)) list2.add(num);
List<List<Integer>> answer = new ArrayList<>();
answer.add(list1);
answer.add(list2);
return answer;
}
=======
//2215. Find the Difference of Two Arrays
class Solution {
public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
for(int num : nums1) set1.add(num);
for(int num : nums2) set2.add(num);
List<Integer> list1 = new ArrayList<>();
List<Integer> list2 = new ArrayList<>();
for(int num : set1) if(!set2.contains(num)) list1.add(num);
for(int num : set2) if(!set1.contains(num)) list2.add(num);
List<List<Integer>> answer = new ArrayList<>();
answer.add(list1);
answer.add(list2);
return answer;
}
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
}