A simple python code, easy to understand


  • 2
    class Solution(object):
        def intToRoman(self, num):
            dict = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
            nums = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
            result = ""
            for letter, n in zip(dict, nums):
                result += letter * int(num / n)
                num %= n
            return result
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.