class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
int len = nums.size();
vector<vector<int>> ans;
sort(nums.begin(), nums.end());
for(int i = 0 ; i < len ; i ++)
{
if( i && (nums[i] == nums[i - 1]) ){
continue;
}
int target = -nums[i];
int left = i + 1;
int right = len - 1;
while(left < right )
{
int key = nums[left] + nums[right];
if( key == target )
{
vector<int> as;
as.push_back( -target );
as.push_back( nums[left]);
as.push_back( nums[right]);
ans.push_back(as);
left ++;
right --;
while( nums[left] == nums[left - 1] )left ++;
while( nums[right] == nums[right + 1] ) right --;
continue;
}else if ( key < target ){
left ++;
}else {
right --;
}
}
}
return ans;
}
};