A java solution easy to understand


  • 0
    E
    public List<Integer> findDisappearedNumbers(int[] nums) {
            Set<Integer> set = new HashSet<Integer>();
            List<Integer> list = new ArrayList<Integer>();
            if(nums.length == 0) return list;
            
            for(int i = 0; i < nums.length; i++) set.add(nums[i]);
     
            for(int i = 1; i <= nums.length; i++){
                if(!set.contains(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.