@@ -0,0 +1,1660 @@
+package problems;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Apublic class Sum4 %7B%0A    public List%3CList%3CInteger%3E%3E fourSum(int%5B%5D num, int target) %7B%0A        final List%3CList%3CInteger%3E%3E out = new ArrayList%3CList%3CInteger%3E%3E();%0A        if (num.length == 0)%0A            return out;%0A%0A        Arrays.sort(num);%0A%0A        for (int i = 0; i %3C num.length - 3; i++) %7B%0A            if (i %3E 0 && num%5Bi%5D == num%5Bi - 1%5D)%0A                continue;%0A%0A            for (int j = i + 1; j %3C num.length - 2; j++) %7B%0A                if (j %3E i + 1 && num%5Bj%5D == num%5Bj - 1%5D)%0A                    continue;%0A%0A                int p = j + 1, q = num.length - 1;%0A                while (p %3C q) %7B%0A                    final int t = num%5Bi%5D + num%5Bj%5D + num%5Bp%5D + num%5Bq%5D;%0A                    if (t == target) %7B%0A                        List%3CInteger%3E list = new ArrayList%3CInteger%3E();%0A                        list.add(num%5Bi%5D);%0A                        list.add(num%5Bj%5D);%0A                        list.add(num%5Bp%5D);%0A                        list.add(num%5Bq%5D);%0A                        out.add(list);%0A%0A                        while (++p %3C q && num%5Bp%5D == num%5Bp - 1%5D)%0A                            ;%0A                        while (--q %3E p && num%5Bq%5D == num%5Bq + 1%5D)%0A                            ;%0A                    %7D else if (t %3C target)%0A                        p++;%0A                    else%0A                        q--;%0A                %7D%0A            %7D%0A        %7D%0A        return out;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Sum4 s = new Sum4();%0A        int%5B%5D num = %7B 1, 2, 2, 5, 8, 5, 4 %7D;%0A        int target = 13;%0A        System.out.println(s.fourSum(num, target));%0A    %7D%0A%7D%0A

Add 4 Sum