-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJY_389481.java
More file actions
53 lines (48 loc) Β· 1.59 KB
/
JY_389481.java
File metadata and controls
53 lines (48 loc) Β· 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
class Solution {
public String solution(long n, String[] bans) {
String answer = "";
int cnt = 0;
PriorityQueue<String> pq = new PriorityQueue<>(new Comparator<String>(){
@Override
public int compare(String o1, String o2) {
if(o1.length() == o2.length()) {
return o1.compareTo(o2);
}
return o1.length() - o2.length();
}
});
for(String s: bans) {
pq.add(s);
}
while(!pq.isEmpty()) {
String s = pq.poll();
long dNum = 0;
// λ¬Έμμ΄μ 10μ§μλ‘ λ³ν
// μ) "abc"λ 26μ§μλ‘ 1*26^2 + 2*26^1 + 3*26^0μ ν΄λΉ
for(int i=s.length()-1; i>=0; i--) {
dNum += (s.charAt(i)-'a'+1) * (Math.pow(26, s.length()-1-i));
}
// λ³νλ 10μ§μκ° cnt+nλ³΄λ€ μμ : κ°λ₯ν λ¬Έμμ΄μ μ μ¦κ°
if(dNum <= cnt + n) {
cnt++;
}
}
n += cnt;
// 10μ§μ -> 26μ§μλ‘ λ°κΏ
StringBuilder sb = new StringBuilder();
while (n > 0) {
long remained = n % 26;
n /= 26;
if (remained == 0) {
n--;
sb.append('z');
} else {
sb.append((char)('a' + remained - 1));
}
}
// System.out.println(sb.reverse().toString());
answer = sb.reverse().toString();
return answer;
}
}