|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
传送门:https://leetcode-cn.com/problems ... ng-shu-xu-lie-lcof/
双指针
- class Solution {
- public:
- vector<vector<int>> ans;
- void add_ans(int a, int b)
- {
- vector<int> temp;
- while (a <= b) temp.push_back(a++);
- ans.push_back(temp);
- }
- vector<vector<int>> findContinuousSequence(int target) {
- int limit = (target + 1) / 2;
- int l = 1, sum = 0;
- for (int r = 1 ; r <= limit; ++r)
- {
- sum += r;
- while (sum > target) sum -= l++;
- if (sum == target) add_ans(l, r);
- }
- return ans;
- }
- };
复制代码 |
|