Skip to content

Commit 3998c84

Browse files
committed
feat: 顺次数
1 parent 6064152 commit 3998c84

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

递归与回溯/顺次数-1291.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @param {number} low
3+
* @param {number} high
4+
* @return {number[]}
5+
*/
6+
let sequentialDigits = function (low, high) {
7+
let lowLen = low.toString().length
8+
let highLen = high.toString().length
9+
let lens = []
10+
for (let i = lowLen; i <= highLen; i++) {
11+
lens.push(i)
12+
}
13+
14+
let res = []
15+
for (let i = 0; i < lens.length; i++) {
16+
let len = lens[i]
17+
for (let start = 1; start <= 10 - len; start++) {
18+
let num = start
19+
20+
for (let n = start + 1; n < start + len; n++) {
21+
num = 10 * num + n
22+
}
23+
if (num <= high && num >= low) {
24+
res.push(num)
25+
}
26+
}
27+
}
28+
29+
return res
30+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy