1
1
# class Solution(object):
2
- # def intToRoman(self, num) :
2
+ # def intToRoman(self, num: int) -> str :
3
3
# """
4
4
# :type num: int
5
5
# :rtype: str
6
6
# """
7
7
#
8
8
class Solution (object ):
9
- # def intToRoman(self, num) :
10
- # # http://www.rapidtables.com/convert/number/how-number-to-roman-numerals.htm
11
- # roman_dim = [[1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],
12
- # [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'], [10, 'X'],
13
- # [9,'IX'], [5, 'V'], [4, 'IV'], [1, 'I']]
14
- # if num == 0:
15
- # return ''
16
- # roman_str = ''
17
- # current, dim = num, 0
18
- # while current != 0:
19
- # while current // roman_dim[dim][0] == 0:
20
- # dim += 1
21
- # while current - roman_dim[dim][0] >= 0:
22
- # current -= roman_dim[dim][0]
23
- # roman_str += roman_dim[dim][1]
24
- # return roman_str
9
+ # def intToRoman(self, num: int) -> str :
10
+ ## http://www.rapidtables.com/convert/number/how-number-to-roman-numerals.htm
11
+ # roman_dim = [[1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],
12
+ # [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'], [10, 'X'],
13
+ # [9,'IX'], [5, 'V'], [4, 'IV'], [1, 'I']]
14
+ # if num == 0:
15
+ # return ''
16
+ # roman_str = ''
17
+ # current, dim = num, 0
18
+ # while current != 0:
19
+ # while current // roman_dim[dim][0] == 0:
20
+ # dim += 1
21
+ # while current - roman_dim[dim][0] >= 0:
22
+ # current -= roman_dim[dim][0]
23
+ # roman_str += roman_dim[dim][1]
24
+ # return roman_str
25
25
26
- def intToRoman (self , num ) :
26
+ def intToRoman (self , num : int ) -> str :
27
27
values = [1000 , 900 , 500 , 400 ,
28
28
100 , 90 , 50 , 40 ,
29
29
10 , 9 , 5 , 4 , 1 ]
@@ -34,7 +34,7 @@ def intToRoman(self, num):
34
34
roman = ''
35
35
i = 0
36
36
while num > 0 :
37
- k = num / values [i ]
37
+ k = num // values [i ]
38
38
for j in range (k ):
39
39
roman += symbols [i ]
40
40
num -= values [i ]
0 commit comments