LeetCode(12)Integer to Roman

题目如下:

Python代码

def intToRoman(self, num):
        """
        :type num: int
        :rtype: str
        """
        M = ['','M','MM','MMM']                                     #千位
        C = ['','C','CC','CCC','CD','D','DC','DCC','DCCC','CM']     #百位
        X = ['','X','XX','XXX','XL','L','LX','LXX','LXXX','XC']     #十位
        I = ['','I','II','III','IV','V','VI','VII','VIII','IX']     #个位
        return M[num/1000]+C[(num%1000)/100]+X[(num%100)/10]+I[num%10]

 

posted @ 2017-07-07 20:08  Single、Dog  阅读(110)  评论(0编辑  收藏  举报