class Solution { public: vector<vector<int> > fourSum(vector<int> &num, int target) { sort(num.begin(),num.end()); vector<vector<int> > res; int* a = &num[0]; int len = num.size(); for (int i = 0; i < len; i++) { if (i > 0 && num[i] == num[i-1]) continue; for (int j = i+1; j < len; j++) { if (j > i+1 && num[j] == num[j-1]) continue; int x = j+1, y = len - 1; while (x < y) { int t = a[i] + a[j] + a[x] + a[y]; if (t == target) { res.push_back({a[i], a[j], a[x], a[y]}); while (x < y && a[x+1] == a[x]) x++; while (x < y && a[y-1] == a[y]) y--; x++; y--; } else if (t > target) { y--; } else { x++; } } } } return res; } };