Skip to content

Commit ec30369

Browse files
authored
Merge pull request #1080 from AlgorithmWithGod/JHLEE325
[20251010] BOJ / G5 / 감소하는 수 / 이준희
2 parents 4de7635 + 801df8c commit ec30369

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
```

0 commit comments

Comments
 (0)