Java one pass beats 88%


  • 0
    P
    public List<Integer> findDuplicates(int[] nums) 
    {
        ArrayList<Integer> result = new ArrayList<Integer>(nums.length);
        int indx = 0, abs_n = 0;
        for(int n : nums)
        {
            abs_n = Math.abs(n);
            indx = abs_n - 1;
            if(nums[indx] > 0)
                nums[indx] *= -1;
            else
                result.add(abs_n);
        }
        
        return result;
    }

Log in to reply
 

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