leetcode--12. Integer to Roman

来源:互联网 发布:永磁旋振治疗仪淘宝 编辑:程序博客网 时间:2024/06/18 04:27

题目:12. Integer to Roman

链接:https://leetcode.com/problems/integer-to-roman/description/

将给定的阿拉伯数字转成罗马数字。

class Solution(object):    romanDict = [("I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", ""),            ("X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", ""),            ("C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", ""),            ("M", "MM", "MMM", "", "", "", "", "", "")]    def intToRoman(self, num):        """        :type num: int        :rtype: str        """        if not str(num):            return ""        return self.romanDict[len(str(num))-1][int(str(num)[0])-1]+self.intToRoman(str(num)[1:len(str(num))])


原创粉丝点击