class Solution {

public:

vector<vector<int>> threeSum(vector<int>& nums) {

```
vector<vector<int>> result;
set<vector<int>> s;
int n = nums.size();
std::sort(nums.begin(),nums.end());
if(nums.size() < 3 || nums[0] >= 1 || nums[n - 1] <= -1)
return result;
for(int i = 0;i < n - 2;i++)
{
int j = i + 1;
int k = n - 1;
while(j < k)
{
if(nums[i] + nums[j] + nums[k] > 0)
k--;
else if(nums[i] + nums[j] + nums[k] < 0)
j++;
else
{
vector<int> vec;
vec.push_back(nums[i]);
vec.push_back(nums[j]);
vec.push_back(nums[k]);
s.insert(vec);
j++;
k--;
}
}
}
set<vector<int>>::iterator it;
for(it = s.begin();it != s.end();++it)
result.push_back(*it);
return result;
}
```

};