JAVA simple


  • 0
    Z

    class Solution {
    public List<Integer> findDisappearedNumbers(int[] nums) {
    List<Integer> list=new ArrayList<Integer>();
    int len=nums.length;

        for(int i=0;i<len;i++){
            int temp=Math.abs(nums[i])-1;
            if(nums[temp]>0){
                nums[temp]=-nums[temp];//做标记并只做一次,重复不会造成影响
            }
        }
        for(int i=0;i<len;i++){
            if(nums[i]>0){
                list.add(i+1);
            }
        }
        return list;
        
    }
    

    }


Log in to reply
 

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