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
| class Solution { public: vector<vector<int> > FindContinuousSequence(int sum) { vector<vector<int>> results; if (sum >= 3) { int a = 1, b = 2, current_sum = 3, mid = sum / 2; while (a <= mid) { if (current_sum < sum) { b++; current_sum += b; } else { if (current_sum == sum) { vector<int> r; for (int i = a; i <= b; i++) { r.push_back(i); } results.push_back(r); } current_sum -= a; a++; } } } return results; } };
|