MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / intToRoman

Method intToRoman

Python/IntegerToRoman.py:6–28  ·  view source on GitHub ↗

:type num: int :rtype: str

(self, num)

Source from the content-addressed store, hash-verified

4"""
5class Solution(object):
6 def intToRoman(self, num):
7 """
8 :type num: int
9 :rtype: str
10 """
11 pattern = [("M",1000),
12 ("CM",900),
13 ("D",500),
14 ("CD",400),
15 ("C",100),
16 ("XC",90),
17 ("L",50),
18 ("XL",40),
19 ("X",10),
20 ("IX",9),
21 ("V",5),
22 ("IV",4),
23 ("I",1)]
24 output = ""
25 for roman, corresonding_number in pattern:
26 output += roman * (num//corresonding_number)
27 num = num % corresonding_number
28 return output

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected