[프로그래머스 LV1] 3진법 뒤집기

popolarburr·2023년 3월 8일
0
post-thumbnail

- 문제




- 풀이


public class Main2 {
    public static void main(String[] args) {
        System.out.println(new Solution().solution(45));
    }
}

class Solution {
    public int solution(int n) {

        StringBuilder sb = new StringBuilder(Integer.toString(n, 3));
        
        int answer = Integer.parseInt(sb.reverse().toString(), 3);
        return answer;
    }
}

- 정리

처음에는 어떻게 풀지 몰랐다. Integer.toString()에 진법변환이 있는 줄도 몰랐다. 검색해본 결과 진법변화를 Integer.toString()으로 할 수 있어서 사용.
하나 배웠다아 !




[링크]:개인저장소

profile
차곡차곡

0개의 댓글