@@ -0,0 +1,1645 @@
+// Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.%0A%0A// Note:%0A// Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a %E2%89%A4 b %E2%89%A4 c %E2%89%A4 d)%0A// The solution set must not contain duplicate quadruplets.%0A//     For example, given array S = %7B1 0 -1 0 -2 2%7D, and target = 0.%0A%0A//     A solution set is:%0A//     (-1,  0, 0, 1)%0A//     (-2, -1, 1, 2)%0A//     (-2,  0, 0, 2)%0A%0Apublic class Solution %7B%0A    public List%3CList%3CInteger%3E%3E fourSum(int%5B%5D num, int target) %7B%0A    %09List%3CList%3CInteger%3E%3E result = new ArrayList%3CList%3CInteger%3E%3E();%0A    %09int len = num.length;%0A    %09if(len == 0) return result;%0A%0A    %09Arrays.sort(num);%0A%0A    %09for(int i = 0; i %3C len - 3; i++)%7B%0A    %09%09if(i != 0 && num%5Bi%5D == num%5Bi - 1%5D) continue;%0A%0A    %09%09for(int j = i + 1; j %3C len - 2; j++)%7B%0A    %09%09%09if(j != i + 1 && num%5Bj%5D == num%5Bj - 1%5D) continue;%0A%0A    %09%09%09int left = j + 1;%0A    %09%09%09int right = len - 1;%0A%0A    %09%09%09while(left %3C right)%7B%0A    %09%09%09%09int sum = num%5Bi%5D + num%5Bj%5D + num%5Bleft%5D + num%5Bright%5D;%0A    %09%09%09%09if(sum %3C target)%7B%0A    %09%09%09%09%09left++;%0A    %09%09%09%09%7Delse if(sum %3E target)%7B%0A    %09%09%09%09%09right--;%0A    %09%09%09%09%7Delse%7B%0A    %09%09%09%09%09List%3CInteger%3E tempList = new ArrayList%3CInteger%3E();%0A    %09%09%09%09%09tempList.add(num%5Bi%5D);%0A    %09%09%09%09%09tempList.add(num%5Bj%5D);%0A    %09%09%09%09%09tempList.add(num%5Bleft%5D);%0A    %09%09%09%09%09tempList.add(num%5Bright%5D);%0A    %09%09%09%09%09result.add(tempList);%0A    %09%09%09%09%09left++;%0A    %09%09%09%09%09right--;%0A    %09%09%09%09%09while(left %3C right && num%5Bleft%5D == num%5Bleft - 1%5D) left++;%0A    %09%09%09%09    while(left %3C right && num%5Bright%5D == num%5Bright + 1%5D) right--;%0A    %09%09%09%09%7D%0A    %09%09%09%7D%0A%0A    %09%09%7D%0A    %09%7D%0A%0A    %09return result;%0A    %7D%0A%7D

add 4sum solution