File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number } low
3
+ * @param {number } high
4
+ * @return {number[] }
5
+ */
6
+ const sequentialDigits = function ( low , high ) {
7
+ const set = new Set ( )
8
+ let start = 0 , end = 0
9
+ for ( let i = 10 ; i >= 0 ; i -- ) {
10
+ if ( low / ( 10 ** i ) >= 1 ) {
11
+ start = ~ ~ ( low / ( 10 ** i ) )
12
+ break
13
+ }
14
+ }
15
+ for ( let i = 10 ; i >= 0 ; i -- ) {
16
+ if ( high / ( 10 ** i ) >= 1 ) {
17
+ end = ~ ~ ( high / ( 10 ** i ) )
18
+ break
19
+ }
20
+ }
21
+ for ( let i = 1 ; i <= 9 ; i ++ ) {
22
+ helper ( `${ i } ` )
23
+ }
24
+
25
+ const res = Array . from ( set )
26
+ res . sort ( ( a , b ) => a - b )
27
+ return res
28
+
29
+ function helper ( s ) {
30
+ // console.log(s)
31
+ if ( + s > high ) return
32
+ if ( + s >= low && + s <= high ) {
33
+ set . add ( + s )
34
+ }
35
+ if ( s [ s . length - 1 ] === '9' ) return
36
+ helper ( `${ s } ${ + s [ s . length - 1 ] + 1 } ` )
37
+ }
38
+ } ;
You can’t perform that action at this time.
0 commit comments