문제풀이

LeetCode(448)::Find All Numbers Disappeared in an Array

문제

 

Find All Numbers Disappeared in an Array - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

문제파악

Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.
  • n == nums.length
  • 1 <= n <= 105
  • 1 <= nums[i] <= n

배열의 길이 까지 수중 배열안에 들어가 있지 않는 수를 찾는 문제이다.

문제풀이

해당 문제는 단순하게 카운트 해주면 될 듯 하다.

class Solution {
    public List<Integer> findDisappearedNumbers(int[] nums) {
        Boolean[] nums_yn = new Boolean[nums.length + 1];
        Arrays.fill(nums_yn, Boolean.FALSE);
        
        for(int i = 0; i < nums.length; i++){
            nums_yn[nums[i]] = true;
        }
        
        List<Integer> solution =new ArrayList<Integer>();
         for(int i = 1; i < nums_yn.length; i++){
            if(nums_yn[i] == false){
                solution.add(i);
            }
        }
        
        return solution;
    }
}

'문제풀이' 카테고리의 다른 글

LeetCode(344)::Reverse String  (0) 2021.11.18
LeetCode(344)::Reverse String  (0) 2021.11.18
LeetCode(189)::Rotate Array  (0) 2021.11.16
LeetCode(43)::Multiply Strings  (0) 2021.11.09
BaekJoon(2447)::별찍기-10  (0) 2021.11.03