LeetCode(12)Integer to Roman
题目如下:
Python代码
def intToRoman(self, num): """ :type num: int :rtype: str """ M = ['','M','MM','MMM'] #千位 C = ['','C','CC','CCC','CD','D','DC','DCC','DCCC','CM'] #百位 X = ['','X','XX','XXX','XL','L','LX','LXX','LXXX','XC'] #十位 I = ['','I','II','III','IV','V','VI','VII','VIII','IX'] #个位 return M[num/1000]+C[(num%1000)/100]+X[(num%100)/10]+I[num%10]