@@ -0,0 +1,1861 @@
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A//15. 3Sum%0A/**%0A * Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.%0A * Note: The solution set must not contain duplicate triplets.%0A * %0A * For example, given array S = %5B-1, 0, 1, 2, -1, -4%5D,%0A * A solution set is:%0A * %5B%0A *      %5B-1, 0, 1%5D,%0A *      %5B-1, -1, 2%5D%0A * %5D%0A * %0A * Tags: Array, Two Pointers%0A * %0A * Similar Problems:  (E) Two Sum (M) 3Sum Closest (M) 4Sum (M) 3Sum Smaller%0A * %0A * @author Xinyue Zhang%0A *%0A */%0A%0Apublic class Solution %7B%0A    public List%3CList%3CInteger%3E%3E threeSum(int%5B%5D nums) %7B%0A        List%3CList%3CInteger%3E%3E res = new ArrayList%3CList%3CInteger%3E%3E();%0A        %0A        Arrays.sort(nums);%0A        int n = nums.length;%0A        %0A        for (int i = 0; i %3C n - 2; i++) %7B%0A            if (nums%5Bi%5D %3E 0) break;%0A            if (i %3E 0 && nums%5Bi%5D == nums%5Bi - 1%5D) continue;%0A            %0A            int j = i + 1, k = n - 1;%0A            %0A            while (j %3C k) %7B%0A                if(nums%5Bi%5D + nums%5Bj%5D + nums%5Bk%5D == 0) %7B%0A                    res.add(Arrays.asList(nums%5Bi%5D, nums%5Bj%5D, nums%5Bk%5D));%0A                    j++;%0A                    k--;%0A                    while (j %3C k && nums%5Bj%5D == nums%5Bj - 1%5D) j++;%0A                    while (j %3C k && nums%5Bk%5D == nums%5Bk + 1%5D) k--;%0A                %7D%0A                else if (nums%5Bj%5D + nums%5Bk%5D %3E -nums%5Bi%5D)%0A                    k--;%0A                else if (nums%5Bj%5D + nums%5Bk%5D %3C -nums%5Bi%5D)%0A                    j++;%0A            %7D%0A        %7D%0A        %0A        return res;%0A    %7D%0A%0A    %0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D nums = %7B-2, 0, 1, 1, 2%7D;%0A        Solution sol = new Solution();%0A        List%3CList%3CInteger%3E%3E res = sol.threeSum(nums);%0A        for (int i = 0; i %3C res.size(); i++)%0A        System.out.println(res.get(i));%0A    %7D%0A%7D%0A

Create 015_3Sum.java