Double pointer
class Solution {
public:
void insertVec(vector<vector<int>>& ret, int low, int high) {
vector<int> tmp;
tmp.reserve(high - low + 1);
for (int i = low; i <= high; ++i) {
tmp.push_back(i);
}
ret.push_back(tmp);
}
vector<vector<int>> findContinuousSequence(int target) {
int left = 1;
int res = 0;
vector<vector<int>> ret;
for (int right = 1; right <= (target >> 1) + 1; ++right) {
res += right;
while (res > target) {
res -= left++;
}
if (res == target) {
insertVec(ret, left, right);
}
}
return ret;
}
};