# ★★☆☆☆ 124 나라의 숫자
# 구현코드
import java.util.ArrayList;
class Solution {
public String solution(int n) {
String answer = "";
ArrayList<Integer> list = new ArrayList<>();
while (n > 0){
list.add(n%3);
n = n / 3;
}
for(int i = 0; i < list.size()-1; i++){
if(list.get(i) == 0) {
list.remove(i);
list.add(i,4);
int carry = list.remove(i + 1) - 1 ;
list.add(i+1,carry);
}
if(list.get(i) < 0){
int removeI = list.remove(i);
list.add(i,3+removeI);
int carry = list.remove(i + 1) - 1 ;
list.add(i+1,carry);
}
}
for(int i = 0; i < list.size(); i++){
if(list.get(i) != 0)
answer = list.get(i) + answer;
}
return answer;
}
}
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
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