Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 580 Bytes

File metadata and controls

26 lines (21 loc) · 580 Bytes

프로그래머스 Level1 : 월간 코드 챌린지 시즌1 3진법 뒤집기

import java.util.Stack;
class Solution {
    public int solution(int n) {
        int answer = 0;
        Stack<Integer> stack = new Stack<>();
        
        while(n!=0){
            stack.push(n % 3);
            n /= 3;
        }
        
        int pow = 0;
        while(!stack.empty()){
            answer += stack.pop() * Math.pow(3,pow);
            pow++;
        }
        
        return answer;
    }
}