class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
set<vector<int>> rst;
sort(nums.begin(), nums.end());
int length = nums.size() - 2;
for (int i = 0; i < nums.size()-2; i++) {
cout << i << endl;
cout << nums.size() - 2;
cout << (0 < length);
int l = i + 1;
int h = nums.size() - 1;
int remain_value = 0 - nums[i];
while (l < h) {
if (nums[l] + nums[h] == remain_value) {
rst.insert({ nums[i],nums[l],nums[h] });
while (l < h && nums[l] == nums[l + 1]) l++;
while (l < h && nums[h] == nums[h - 1]) h--;
l++;
h--;
}
else if (nums[l] + nums[h] < remain_value) {
l++;
}
else {
h--;
}
}
}
return vector<vector<int>>(rst.begin(), rst.end());
}
};
【数组】【二分】leetcode.15三数之和
最新推荐文章于 2024-05-31 13:03:47 发布