Skip to content

Commit 9547cbe

Browse files
committed
Create 面试题57 - II. 和为s的连续正数序列.js
1 parent 12a241a commit 9547cbe

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number} target
3+
* @return {number[][]}
4+
*/
5+
var findContinuousSequence = function(target) {
6+
const result = [];
7+
let cur = [];
8+
let sum = 0;
9+
for (let i = 1; i < target; i++) {
10+
cur.push(i);
11+
sum += i;
12+
while (sum > target) {
13+
sum -= cur.shift();
14+
}
15+
if (sum === target) {
16+
result.push(cur.slice(0));
17+
}
18+
}
19+
return result
20+
};

0 commit comments

Comments
 (0)