【LEETCODE】12-Integer to Roman

来源:互联网 发布:云计算 校园招聘 编辑:程序博客网 时间:2024/06/06 04:19

Given an integer, convert it to a roman numeral.

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


题意:

给一个整数,将它转换成罗马数字,给的整数的范围在 1-3999


参考:

http://www.cnblogs.com/zuoyuan/p/3779581.html




class Solution(object):    def intToRoman(self, num):        """        :type num: int        :rtype: str        """        values = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ]        numerals = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ]                r=''                for i in range(len(values)):            while num>=values[i]:                num-=values[i]                r+=numerals[i]                    return r


0 0