leetcode448. 找到所有数组中消失的数字(java)

简单题重拳出击

还是错了一点点 

emo

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

        for(int num : nums){
            int x = (num - 1) % n;
            nums[x] += n;
        }
        for(int i = 0; i < n; i++){
            if(nums[i] <= n){
                list.add(i + 1);
            }
        } 
        return list;
    }
}

你可能感兴趣的:(学习做题leetcode,java,leetcode)