File tree Expand file tree Collapse file tree
src/main/java/com/fishercoder/solutions/thirdthousand Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments