File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+ static ArrayList<Long > list = new ArrayList<> ();
8+
9+ public static void main (String [] args ) throws IOException {
10+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ StringTokenizer st;
12+
13+ int n = Integer . parseInt(br. readLine());
14+
15+ for (int i = 0 ; i <= 9 ; i++ ) {
16+ dfs(i, 1 );
17+ }
18+
19+ Collections . sort(list);
20+
21+ if (n >= list. size()) {
22+ System . out. println(- 1 );
23+ } else {
24+ System . out. println(list. get(n));
25+ }
26+ }
27+
28+ static void dfs (long num , int depth ) {
29+ list. add(num);
30+
31+ long lastDigit = num % 10 ;
32+ if (lastDigit == 0 ) return ;
33+
34+ for (int next = 0 ; next < lastDigit; next++ ) {
35+ dfs(num * 10 + next, depth + 1 );
36+ }
37+ }
38+ }
39+ ```
You can’t perform that action at this time.
0 commit comments