标签:end ids start begin public art last tco --
class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(), nums.end()); vector<vector<int> > validSet; for (int i = 0; i < nums.size(); ++i){ if (i >= 1 && nums[i] == nums[i-1])continue; int exp = -nums[i]; int start = i+1; int end = nums.size()-1; while (start < end) { int sum = nums[start] + nums[end]; if (sum == exp){ bool good = true; if (validSet.size() > 0){ vector<int>& last = validSet[validSet.size()-1]; if (nums[i] == last[0] && nums[start] == last[1] && nums[end] == last[2]){ good = false; } } if (good){ vector<int> res; res.push_back(nums[i]); res.push_back(nums[start]); res.push_back(nums[end]); validSet.push_back(res); } start ++; end --; } else if (sum < exp){ start ++; } else { end --; } } } return validSet; } };
标签:end ids start begin public art last tco --
原文地址:http://www.cnblogs.com/nosaferyao/p/7906098.html