Skip to content

Commit 5279809

Browse files
authored
Update 1291-sequential-digits.js
1 parent 53a5323 commit 5279809

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

1291-sequential-digits.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
/**
2+
* @param {number} low
3+
* @param {number} high
4+
* @return {number[]}
5+
*/
6+
const sequentialDigits = function(low, high) {
7+
const res = []
8+
9+
let q = []
10+
for(let i = 1; i <= 9; i++) q.push(i)
11+
12+
while(q.length) {
13+
const tmp = []
14+
const size = q.length
15+
for(let i = 0; i < size; i++) {
16+
const cur = q[i]
17+
if(cur >= low && cur <= high) {
18+
res.push(cur)
19+
}
20+
if(cur > high) break
21+
const last = cur % 10
22+
if(last === 9) continue
23+
tmp.push(cur * 10 + last + 1)
24+
}
25+
26+
q = tmp
27+
}
28+
29+
return res
30+
};
31+
32+
// another
33+
134
/**
235
* @param {number} low
336
* @param {number} high

0 commit comments

Comments
 (0)