12. 정수를 로마 숫자로 | LeetCode | Top Interview 150 | 코딩 질문

발행: (2025년 12월 26일 오전 06:53 GMT+9)
1 min read
원문: Dev.to

Source: Dev.to

문제 링크

https://leetcode.com/problems/integer-to-roman/

leetcode 12

풀이

class Solution {
    public String intToRoman(int num) {

        int[] values = {
            1000, 900, 500, 400,
            100, 90, 50, 40,
            10, 9, 5, 4,
            1
        };

        String[] symbols = {
            "M", "CM", "D", "CD",
            "C", "XC", "L", "XL",
            "X", "IX", "V", "IV",
            "I"
        };

        StringBuilder ans = new StringBuilder();

        for (int i = 0; i = values[i]) {
                num -= values[i];
                ans.append(symbols[i]);
            }
        }

        return ans.toString();
    }
}
Back to Blog

관련 글

더 보기 »