题解 | #和为S的连续正数序列#
和为S的连续正数序列
https://www.nowcoder.com/practice/c451a3fd84b64cb19485dad758a55ebe
#include <vector> class Solution { public: vector<vector<int> > FindContinuousSequence(int sum) { vector<vector<int>> result; vector<int> data; if(sum==0){ return result; } int j; int rank; //int flag=0; for(int i=1;i<=sum-1;i+=1){ rank=0; for(int j=i;j<=sum-1;j+=1){ rank+=j; data.push_back(j); if(rank==sum){ result.push_back(data); break; } } if(data.size()>0){ data.clear(); } } return result; } };