Guest User

Untitled

a guest
Oct 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. class Solution:
  2. def intToRoman(self, num):
  3. """
  4. :type num: int
  5. :rtype: str
  6. """
  7. # Symbol Value
  8. # I 1
  9. # V 5
  10. # X 10
  11. # L 50
  12. # C 100
  13. # D 500
  14. # M 1000
  15.  
  16. dict = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
  17. nums = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
  18. result = ""
  19. for letter, n in zip(dict, nums):
  20. result += letter * int(num / n)
  21. num %= n
  22. return result
Add Comment
Please, Sign In to add comment