diff --git a/012._Integer_to_Roman.md b/012._Integer_to_Roman.md index a4d377b672929abaf80dd275169f5d9c12fdeb14..529a323e8a85bd3b60cf3092bd02adb94e15cec6 100644 --- a/012._Integer_to_Roman.md +++ b/012._Integer_to_Roman.md @@ -64,22 +64,35 @@ via 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 ```