Skip to content

Commit 2c6ba16

Browse files
update 2215
1 parent c2156eb commit 2c6ba16

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

  • src/main/java/com/fishercoder/solutions/thirdthousand

src/main/java/com/fishercoder/solutions/thirdthousand/_2215.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,34 @@ public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
2222
return new ArrayList<>(Arrays.asList(list1, list2));
2323
}
2424
}
25+
26+
public static class Solution2 {
27+
28+
public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
29+
List<List<Integer>> ans = new ArrayList<>();
30+
Set<Integer> list1 = new HashSet<>();
31+
Set<Integer> list2 = new HashSet<>();
32+
Set<Integer> set1 = new HashSet<>();
33+
for (int num : nums1) {
34+
set1.add(num);
35+
}
36+
Set<Integer> set2 = new HashSet<>();
37+
for (int num : nums2) {
38+
set2.add(num);
39+
}
40+
for (int num : nums1) {
41+
if (!set2.contains(num)) {
42+
list1.add(num);
43+
}
44+
}
45+
ans.add(new ArrayList<>(list1));
46+
for (int num : nums2) {
47+
if (!set1.contains(num)) {
48+
list2.add(num);
49+
}
50+
}
51+
ans.add(new ArrayList<>(list2));
52+
return ans;
53+
}
54+
}
2555
}

0 commit comments

Comments
 (0)