풀이 방법
감소하는 수의 최대는 9876543210이기 때문에 최대 수가 나올때까지 모든 수를 구해주고 순서대로 정렬해주었다.
내 코드
package com.company;
import java.io.*;
import java.util.*;
public class Main {
static int N;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
ArrayList<String> list = new ArrayList<>();
for (long i = 0; i < 10; i++) {
list.add(i + "");
}
String x = "";
int index = 0;
while (!x.equals("9876543210")) {
x = list.get(index);
int temp = Integer.parseInt(x.charAt(0) + "");
for (long i = temp + 1; i < 10; i++) {
list.add(i + x);
}
index++;
}
Collections.sort(list, (s1, s2) -> {
if (Long.parseLong(s1) - Long.parseLong(s2) > 0)
return 1;
return -1;
});
System.out.println(N >= list.size() ? -1 : list.get(N));
}
}
'코딩테스트 > [백준] 코딩테스트 연습' 카테고리의 다른 글
공유기 설치 - 2110번 (0) | 2021.12.01 |
---|---|
램프 - 1034번 (0) | 2021.11.26 |
리모컨 - 1107번 (0) | 2021.11.23 |
미친 로봇 - 1405번 (0) | 2021.11.22 |
음식 평론가 - 1188번 (0) | 2021.11.22 |