未验证 提交 67f0ce83 编写于 作者: K KEQI HUANG 提交者: GitHub

Update 012._Integer_to_Roman.md

上级 dc80e46d
......@@ -64,22 +64,35 @@ via <http://www.cnblogs.com/cacique/archive/2012/02/23/2364377.html>
AC代码
```
```python
class Solution(object):
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
lookup = {'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}
romanSt = ''
lookup = {
'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
}
romanStr = ''
for symbol, val in sorted(lookup.items(), key = lambda t: t[1], reverse = True):
while num >= val:
romanSt += symbol
romanStr += symbol
num -= val
return romanSt
return romanStr
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册