728x90
https://school.programmers.co.kr/learn/courses/30/lessons/68935
728x90
메모리: 80.4 MB, 시간: 0.06 ms
사용 알고리즘: 구현
class Solution {
public int solution(int n) {
// n보다 작거나 같은 수 중 가장 큰 3의 제곱 구하기
int pow = 0;
while(n >= (int)Math.pow(3, pow)) pow++;
pow--;
// 3진법 구하고 뒤집어 10진법으로 변환
int answer = 0;
int tmp;
for(int i = pow; i >= 0; i--) {
tmp = n / (int)(Math.pow(3, i));
answer += tmp * (int)(Math.pow(3, pow - i));
n %= (int) Math.pow(3, i);
}
return answer;
}
}
728x90
'Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스, 131705] 삼총사 (java) (0) | 2025.01.19 |
---|---|
[프로그래머스, 12982] 예산 (java) (0) | 2025.01.14 |
[프로그래머스, 17682] [1차] 다트 게임 (java) (0) | 2025.01.14 |
[프로그래머스, 340213] [PCCP 기출문제] 1번 / 동영상 재생기 (java) (0) | 2025.01.14 |
[프로그래머스, 86051] 없는 숫자 더하기 (java) (0) | 2025.01.13 |