class Solution {
public:
vector<vector<int>> fourSum(vector<int>& nums, int target) {
vector<vector<int>> ans;
long long tmp=target;
sort(nums.begin(),nums.end());
for(int a=0;a<nums.size();a++)
{
if(a&&nums[a]==nums[a-1])
continue;
for(int b=a+1;b<nums.size();b++)
{
if(b!=a+1&&nums[b]==nums[b-1])
continue;
for(int c=b+1,d=nums.size()-1;c<d;c++)//双指针
{
if(c!=b+1&&nums[c]==nums[c-1])
continue;
while(d!=c+1&&(long long)nums[a]+nums[b]+nums[c]+nums[d-1]>=tmp)
d--;
if((long long)nums[a]+nums[b]+nums[c]+nums[d]==tmp)
ans.push_back({nums[a],nums[b],nums[c],nums[d]});
}
}
}
return ans;
}
};
标签:tmp,四数,nums,18,long,vector,ans,LeetCode
From: https://www.cnblogs.com/tangxibomb/p/17224311.html