Java easy solutions, use boolean arrays


  • 0
    Z
    class Solution {
        public List<Integer> findDisappearedNumbers(int[] nums) {
            int len = nums.length;
            boolean[] set = new boolean[len+1];
            for(int i: nums){
                set[i] = true;
            }
            List<Integer> list = new ArrayList<>();
            for(int i=1;i<=len;i++){
                if(!set[i])
                    list.add(i);
            }
            return list;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.