其他分享
首页 > 其他分享> > leetcode第12题整数转罗马数字--hash

leetcode第12题整数转罗马数字--hash

作者:互联网

 先上自己写的代码

class Solution(object):
    def intToRoman(self, num):
        """
        :type num: int
        :rtype: str
        也像个自动机
        """
        list_re=[]
        dict_Roman={
            0:['','','',''],
            1:['I','X','C','M'],
            2:['II','XX','CC','MM'],
            3:['III','XXX','CCC','MMM'],
            4:['IV','XL','CD'],
            5:['V','L','D'],
            6:['VI','LX','DC'],
            7:['VII','LXX','DCC'],
            8:['VIII','LXXX','DCCC'],
            9:['IX','XC','CM']}
        bit=0
        while num>0:
            list_re.append(dict_Roman[num%10][bit])
            bit+=1
            num=num/10
        return ''.join(list_re[::-1])

标签:12,hash,--,list,re,Roman,num,dict,bit
来源: https://blog.csdn.net/lxhseph/article/details/122466511