Skip to main content

Leetcode 2215

· One min read
Junhe Chen

Three easy question in a row, next might be hard. there is not much to talk about for this question.

class Solution {
public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
Set<Integer> seen1 = new HashSet<>();
Set<Integer> seen2 = new HashSet<>();
for(int num : nums1){
seen1.add(num);
}
Set<Integer> distinct2 = new HashSet<>();
for(int num : nums2){
seen2.add(num);
if(!seen1.contains(num)){
distinct2.add(num);
}
}
Set<Integer> distinct1 = new HashSet<>();
for(int num : nums1){
if(!seen2.contains(num)){
distinct1.add(num);
}
}
return List.of(new ArrayList<>(distinct1),new ArrayList<>(distinct2));
}
}