标签:style blog io ar color sp for on div
class Solution { public: vector<vector<int> > ThreeSum(int a[], int n, int target) { vector<vector<int> > ret; for (int i = 0; i < n; i++) { if(i>0 && a[i] == a[i - 1]) continue; int begin = i, end = n - 1; while (begin <= end) { int sum = a[i] + a[begin] + a[end]; if (sum == target) { vector<int> res = { a[i], a[begin], a[end] }; ret.push_back(res); begin++; end--; while (begin < end && a[begin] == a[begin - 1]) begin++; while (begin<end && a[end] == a[end + 1]) end--; } else if (sum>target) { end--; } else { begin++; } } } return ret; } };
3 sum allow number used multi times
标签:style blog io ar color sp for on div
原文地址:http://www.cnblogs.com/jobfindingnotes/p/4116628.html