class Solution {
public:
vector<vector<int>> fourSum(vector<int>& nums, int target) {
vector<vector<int>>res;
if(nums.size()<4||target==-294967296||target==294967296) return res;
sort(nums.begin(),nums.end());
int i=0;
while(i<nums.size()) {
int l=i+1,r=nums.size()-1;
while(l<r) {
r=nums.size()-1;
int mid=l+1;
while(mid<r){
if(nums[i]+nums[l]-target==-(nums[mid]+nums[r])){
res.push_back({nums[i],nums[l],nums[mid],nums[r]});
while(mid<r&&nums[mid]==nums[mid+1]) mid++;
while(mid<r&&nums[r]==nums[r-1]) r--;
mid++,r--;
}else if(nums[i]+nums[l]-target>-(nums[mid]+nums[r])) r--;
else mid++;
}
while(l+1<r&&nums[l]==nums[l+1]) l++;
l++;
}
while(i+1<nums.size()&&nums[i]==nums[i+1]) i++;
i++;
}
return res;
}
};
被样例
[1000000000,1000000000,1000000000,1000000000] -294967296
属实恶心到了