My 1 pass Java solution


  • 0
    R

    '''public List<Integer> findDuplicates(int[] nums) {
    List<Integer> dups=new ArrayList<Integer>();
    for(int i=0;i<nums.length;i++){
    if(nums[Math.abs(nums[i])-1]<0){
    dups.add(Math.abs(nums[i]));
    }
    else{
    nums[Math.abs(nums[i])-1]=-nums[Math.abs(nums[i])-1];
    '''
    }
    }
    return dups;
    }


Log in to reply
 

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