LeetCode : No12 Integer to Roman

来源:互联网 发布:sql 包含某几个字符 编辑:程序博客网 时间:2024/05/16 12:48


题目链接:

https://leetcode.com/problems/integer-to-roman/

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

罗马字符:

1:I、5:V、10:X、50:L、100:C、500:D、1000:M

 

耗时:302ms

 

class Solution:    # @param {integer} num    # @return {string}    def intToRoman(self, num):        Roman = ['','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']        RoStr = ''        RoPi = 0        while (num>0):            remainder = num%10            num = num/10            RoStr = Roman[remainder+RoPi] + RoStr            RoPi += 10        return RoStr


 

 

0 0
原创粉丝点击