문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
nums[i]가 [1, n] 범위의 n개의 정수가 있는 배열 nums가 주어졌을 때, nums에 나타나지 않는 [1, n] 범위의 모든 정수로 이루어진 배열을 반환해라.
#1
Input: nums = [4, 3, 2, 7, 8, 2, 3, 1]
Output: [5, 6]
#2
Input: nums = [1, 1]
Output: [2]
class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
Set<Integer> numSet = new HashSet<>();
for(int num : nums){
numSet.add(num);
}
List<Integer> result = new ArrayList<>();
for(int i = 1; i <= nums.length; i++){
if(!numSet.contains(i)){
result.add(i);
}
}
return result;
}
}