public String solution(int n) {
StringBuilder ternaryDigits = new StringBuilder();
while (n != 0) {
if (n % 3 != 0) {
ternaryDigits.append(n % 3);
n /= 3;
} else {
ternaryDigits.append(4);
n = n / 3 - 1;
}
}
return ternaryDigits.reverse().toString();
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/12899