해결방법
- n을 3으로 나눈 나머지를 문자열에 앞에서부터 담기
- 3진법 문자열을 10진수로 변환
활용코드
n진법 -> 10진법 변환
Integer.parseInt(str, n);
전체코드
class Solution {
public int solution(int n) {
int answer = 0;
String three = "";
while(n>0) {
three += n%3;
n = n/3;
}
answer = Integer.parseInt(three, 3);
return answer;
}
}