Advertisement
Guest User

Integer to Roman

a guest
Feb 9th, 2021
160
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def intToRoman(self, num: int) -> str:
  2.     roman = {1000:"M", 900:"CM", 500:"D", 400:"CD", 100:"C", 90:"XC", 50:"L", 40:"XL", 10:"X", 9:"IX", 5:"V", 4:"IV", 1:"I"}
  3.     ans = []
  4.     for k, v in roman.items():
  5.         ans.append(num//k * v)
  6.         num %= k
  7.     return "".join(ans)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement