Very simple solution with boolean


  • 0
    E
     public List<Integer> findDisappearedNumbers(int[] nums) {
            
            
            boolean [] values=new boolean[nums.length+1];
            List<Integer> out=new LinkedList<>();
            
            
            for(int i=0;i<nums.length;i++)
                values[nums[i]]=true;
            
            for(int i=1;i<values.length;i++)
                if(!values[i])
                    out.add(i);
            
            return out;
            
            
            
        }
    
    

    The default value for boolean is false, so iterate the first time and mark every number with true ,then iterate again if it false add it to output list


Log in to reply
 

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