문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
인덱스가 0부터 시작하는 2개의 배열 nums1과 nums2가 주어지고, 사이즈가 2인 리스트 answer를 반환해라.
#1
Input: nums1 = [1, 2, 3], nums2 = [2, 4, 5]
Output: [[1, 3], [2, 6]]
#2
Input: nums1 = [1, 2, 3, 3], nums2 = [1, 1, 2, 2]
Output: [[3], []]
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);
}
}
return Arrays.asList(list1, list2);
}
}