public class Solution {
    public List<Integer> findDuplicates(int[] nums) {
        Set<Integer> set = new HashSet<>();
        List<Integer> res = new LinkedList<>();
        for(int i=0;i<nums.length;i++){
            if(set.contains(nums[i])){
                res.add(nums[i]);
            }else{
                set.add(nums[i]);
            }
        }
        
        return res;
    }
}
@@ -388,9 +388,557 @@
 ;%0A    %7D%0A
+/*     when find a number i, flip the number at position i-1 to negative.  1 =%3Cnums%5Bi%5D%3C=n(n size of array)%0A     if the number at position i-1 is already negative, i is the number that occurs twice.*/%0A    public List%3CInteger%3E findDuplicates2(int%5B%5D nums) %7B%0A        List%3CInteger%3E res = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C nums.length; ++i) %7B%0A            int index = Math.abs(nums%5Bi%5D)-1;%0A            if (nums%5Bindex%5D %3C 0)%0A                res.add(Math.abs(index+1));%0A            nums%5Bindex%5D = -nums%5Bindex%5D;%0A        %7D%0A        return res;%0A    %7D%0A
 %7D

ADD BETTER SOLUTION