【每日一题】12. 整数转罗马数字

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

class Solution {
    public String intToRoman(int num) {
        String[] str = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
        int[] nums = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
        StringBuilder res = new StringBuilder();
        for(int i = str.length - 1; i >= 0; i--){
            while(num >= nums[i]){
                res.append(str[i]);
                num -= nums[i];
            }
        }
        return res.toString();
    }
}

原文地址:https://www.cnblogs.com/realzhaijiayu/p/14768113.html