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