vector<vector<int> > FindContinuousSequence(int sum) { vector<vector<int> > result; if(sum<1) return result; int left=1, right=2; int count=left+right; while(left<right && right<sum) { if(count==sum) { vector<int> temp; for(int i=left; i<=right; i++) temp.push_back(i); result.push_back(temp); right++; count+=right; } else if(count<sum) { right++; count+=right; } else { count-=left; left++; } } return result; }
原文:http://www.cnblogs.com/zhwcs/p/7577053.html