class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
vector<vector<int>> res;
sort(nums.begin(), nums.end());
for(int i=0;i<nums.size();i++){
if(i > 0 && nums[i]==nums[i-1]) continue;
int l = i + 1;
int r = nums.size() - 1;
while(l < r){
int s = nums[i] + nums[l] + nums[r];
if(s < 0) l++;
else if(s > 0) r--;
else{
res.push_back({nums[i],nums[l],nums[r]}); //这个vector的操作很关键
while(l < r && nums[l] == nums[l+1]) l++;
while(l < r && nums[r] == nums[r-1]) r--;
l++;r--;
}
}
}
return res;
}
};