整数转罗马数字
Posted dolisun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了整数转罗马数字相关的知识,希望对你有一定的参考价值。
思路:https://leetcode-cn.com/problems/integer-to-roman/solution/tan-xin-suan-fa-by-liweiwei1419/
class Solution(object):
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
numbers = [('M',1000), ('CM',900), ('D',500), ('CD',400), ('C',100), ('XC',90), ('L',50), ('XL',40), ('X',10), ('IX',9), ('V',5), ('IV',4), ('I',1)]
res = []
for s, n in numbers:
if num == 0:
break
elif num >= n:
res += [s]*(num//n)
num %= n
return ''.join(res)
以上是关于整数转罗马数字的主要内容,如果未能解决你的问题,请参考以下文章