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])

上一篇:Flash简介


下一篇:[Systemverilog学习笔记] class