还需优化。。。
class Solution: def intToRoman(self, num: int) -> str: memo={'I':1,'IV':4,'V':5,'IX':9,'X':10,'XL':40,'L':50,'XC':90,'C':100,'CD':400,'D':500,'CM':900,'M':1000} a='' res=num b=[] for k in memo.keys(): b.append(k) while res!=0: if res>=memo[b[-1]]: #print(b[-1]) res-=memo[b[-1]] a+=b[-1] else: for i in range(len(b)-1): if memo[b[i]]<=res<memo[b[i+1]]: #print(b[i]) res-=memo[b[i]] a+=b[i] return a
执行用时 :92 ms, 在所有 python3 提交中击败了27.24%的用户
内存消耗 :13.8 MB, 在所有 python3 提交中击败了5.26%的用户
——2019.10.17