package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/find-all-duplicates-in-an-array/
 */
public class Problem442 {
    public List<Integer> findDuplicates(int[] nums) {
        List<Integer> result = new ArrayList<>();
        // TODO
        return result;
    }

    public static void main(String[] args) {
        Problem442 prob = new Problem442();
        System.out.println(prob.findDuplicates(new int[]{4, 3, 2, 7, 8, 2, 3, 1})); // [2, 3]
    }
}

@@ -280,15 +280,297 @@
     
-// TODO
+for (int i = 0; i %3C nums.length; i++) %7B%0A            if (nums%5Bi%5D != i + 1) %7B%0A                int to = nums%5Bi%5D - 1;%0A                nums%5Bi%5D = 0;%0A                int n = swap(nums, to);%0A                if (n != 0) %7B%0A                    result.add(n);%0A                %7D%0A            %7D%0A        %7D
 %0A   
@@ -605,21 +605,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -619,172 +619,272 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem442 prob = new Problem442();%0A        System.out.println(prob.findDuplicates(new int%5B%5D%7B4, 3, 2, 7, 8, 2, 3, 1%7D)); // %5B2, 3%5D
+int swap(int%5B%5D nums, int from) %7B%0A        if (nums%5Bfrom%5D == from + 1) %7B%0A            return nums%5Bfrom%5D;%0A        %7D%0A        int val = nums%5Bfrom%5D;%0A        nums%5Bfrom%5D = from + 1;%0A        if (val == 0) %7B%0A            return 0;%0A        %7D%0A        return swap(nums, val - 1);
 %0A   

Solve problem 442