Java


  • 0
    D
    class Solution {
        public List<Integer> findDisappearedNumbers(int[] nums) {
            if (nums == null) {
                throw new NullPointerException();
            }
            Set<Integer> result = new HashSet<Integer>(nums.length);
            for (int i = 0, max = nums.length; i < max; i ++) {
                nums[Math.abs(nums[i]) - 1]  = - Math.abs(nums[Math.abs(nums[i]) - 1]);
                if (nums[i] > 0) {
                    result.add(i + 1);
                }
                result.remove(Integer.valueOf(Math.abs(nums[i])));
            }
            return new ArrayList<>(result);
        }
    }
    

Log in to reply
 

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