Java Solution


  • 0
    C
    public List<Integer> findDuplicates(int[] nums) {
            List<Integer> result = new ArrayList<Integer>();
            for(int i=0; i<nums.length; i++){
                int val = Math.abs(nums[i]);
                if(nums[val - 1] < 0){
                    result.add(val);
                }
                
                nums[val - 1] *= -1;
            }
            
            return result;
        }
    

Log in to reply
 

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