GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/3Sum.cpp at master · handongfeng/leetcode Expand file tree/ Copy path3Sum.cppMore file actions 54 lines (50 loc) · 938 Bytes / Copy path3Sum.cppFile metadata and controls54 lines (50 loc) · 938 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 class Solution { public: vector<vector<int> > threeSum(vector<int> &num) { // Start typing your C/C++ solution below // DO NOT write int main() function int n= num.size(); int _min =INT_MAX; int _minSum =0; vector<vector<int> > ret; set<vector<int> > retset; if(n<3) return ret; else { sort(num.begin(),num.end()); for(int i=0;i<n-2;i++) { int j= i+1; int k=n-1; while(j<k) { int sum = num[i]+num[j]+num[k]; if(sum<0) { j++; } else if(sum>0) { k--; } else { vector<int> v; v.push_back(num[i]); v.push_back(num[j]); v.push_back(num[k]); retset.insert(v); j++; k--; } } } } set<vector<int> >::iterator it; for(it=retset.begin();it!=retset.end();it++) { ret.push_back((*it)); } return ret; } }; |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |