AcWing 76. 和为S的连续正数序列
原题链接
中等
作者:
cyb-包子
,
2021-07-19 14:01:52
,
所有人可见
,
阅读 229
/**
* @param {number} sum
* @return {number[][]}
*/
var findContinuousSequence= function(target) {
let list = [];
let left = 1;
let right = 1;
let sum = 0;
while(left < target / 2){
if(sum < target) {
sum += right;
right ++;
}else if(sum > target) {
sum -= left;
left ++;
}else {
let arr = [];
// console.log(left, right);
for(let i = left; i < right; i ++){
arr.push(i);
}
list.push(arr);
sum -= left;
left++;
}
}
return list;
};