标签:set class begin bre end code while ++i cto
class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { set<vector<int>> res; sort(nums.begin(), nums.end()); for (int k = 0; k < nums.size(); ++k) { if (nums[k] > 0) break; int target = 0 - nums[k]; int i = k + 1, j = nums.size() - 1; while (i < j) { if (nums[i] + nums[j] == target) { res.insert({nums[k], nums[i], nums[j]}); while (i < j && nums[i] == nums[i + 1]) ++i; while (i < j && nums[j] == nums[j - 1]) --j; ++i; --j; } else if (nums[i] + nums[j] < target) ++i; else --j; } } return vector<vector<int>>(res.begin(), res.end()); } };
标签:set class begin bre end code while ++i cto
原文地址:http://www.cnblogs.com/wangkun1993/p/6372215.html