:type num: int :rtype: str
(self, num)
| 4 | """ |
| 5 | class 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 |
nothing calls this directly
no outgoing calls
no test coverage detected