12,整数转罗马数字

class Solution:
    def intToRoman(self, num: int) -> str:
        roman_dict = {
            1000:'M', 900:'CM', 500:'D', 400:'CD',
            100:'C', 90:'XC', 50:'L', 40:'XL',
            10:'X', 9:'IX', 5:'V', 4:'IV', 1:'I'
        }
        rlt = ""
        for key in roman_dict.keys():
            while key <= num != 0:
                num -= key
                rlt+=roman_dict[key]
        return rlt

猜你喜欢

转载自blog.csdn.net/weixin_42758299/article/details/88537727
今日推荐