# 4Sum

  class Solution {
public:
vector<vector<int> > fourSum(vector<int> &num,int target) {

int n = num.size();
sort(num.begin(), num.end());
vector<vector<int> > res;
if(n<4) return res;
for(int i = 0; i < n-2; i++)
for(int j=i+1;j<n-1;j++)
{
int target2 = target - num[i]-num[j];
twoSum(num,i, j+1, target2, res);
}
sort(res.begin(),res.end());
res.erase(unique(res.begin(),res.end()),res.end());
return res;
}
void twoSum(vector<int> &sortedNum, int i,int start, int target, vector<vector<int> >&res)
{
int head = start, tail = sortedNum.size() - 1;
{
int tmp = sortedNum[head] + sortedNum[tail];
if(tmp < target)
else if(tmp > target)
tail--;
else
{
tail--;
}
}
}
};

#### LeetCode 之 4Sum 的四种实现

2015-08-24 13:15:33

#### [C++]LeetCode: 71 4Sum && kSum总结

2015-01-06 10:43:37

#### 18. 4Sum Leetcode Python

2015-01-17 11:55:43

#### 4Sum -- LeetCode

2014-05-01 04:13:26

#### LeetCode 18 4Sum (C,C++,Java,Python)

2015-05-10 15:04:02

#### (Java)LeetCode-18. 4Sum

2016-05-30 19:59:46

#### LeetCode 454 4Sum II 题解

2017-03-12 19:33:58

#### 【leetcode】454. 4Sum II【M】

2016-11-22 13:11:12

#### Leetcode: 4Sum

2013-10-08 12:51:59

#### Leetcode 454. 4Sum II 四数之和2 解题报告

2016-11-16 22:45:38