K-th Smallest in Lexicographical Order LeetCode solution in JavaScript

1
 public int findKthNumber(int n, int k) {
2
lexicalorder(n);
3
int a= ans.get(k-1);
4
return a;
5
}
6

7
public void lexicalorder(int n)
8
{
9
for(int i=1; i<=9; i++){
10
helper(i,n);
11
}
12
}
13

14
public void helper(int x, int n){
15
if(x<=n){
16
ans.add(x);
17
}
18
else{
19
return;
20
}
21
for(int i=0; i<=9; i++){
22
helper(x*10+i, n);
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0