LeetCode/2021-Oct/Oct5thFindAllDuplicatesInAnArray.java
// occurs twice. (C: this works, because the problem constrains)
occurs twice. (C: this works, because the problem constrains)
occurs twice . ( C : this works because the problem constrains )
public List<Integer> findDuplicates2(int[] nums) {
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < nums.length; ++i) {
            int index = Math.abs(nums[i]) - 1;
            if (nums[index] < 0)
                res.add(Math.abs(index + 1));
            nums[index] = -nums[index];
        }
        return res;
    }
public List < Integer > findDuplicates2 ( int [ ] nums ) { List < Integer > res = new ArrayList < > ( ) ; for ( int i = 0 ; i < nums . length ; ++ i ) { int index = Math . abs ( nums [ i ] ) - 1 ; if ( nums [ index ] < 0 ) res . add ( Math . abs ( index + 1 ) ) ; nums [ index ] = - nums [ index ] ; } return res ; }
occurs twice.
occurs twice .