mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-23 09:38:27 +00:00
Update roman_numerals.py
This commit is contained in:
parent
1e48591d72
commit
f5cdd52aa0
|
@ -8,8 +8,8 @@ ROMAN = [
|
||||||
]
|
]
|
||||||
def roman_to_int(roman: str) -> int:
|
def roman_to_int(roman: str) -> int:
|
||||||
"""
|
"""
|
||||||
Convert a Roman numeral to an integer, supporting Vinculum notation (underscore _ represents 1000 times).
|
Convert a Roman numeral to an integer, supporting Vinculum notation (underscore _ represents 1000 times).
|
||||||
LeetCode No. 13 Roman to Integer
|
LeetCode No. 13 Roman to Integer
|
||||||
Given a roman numeral, convert it to an integer.
|
Given a roman numeral, convert it to an integer.
|
||||||
Input is guaranteed to be within the range from 1 to 3999.
|
Input is guaranteed to be within the range from 1 to 3999.
|
||||||
https://en.wikipedia.org/wiki/Roman_numerals
|
https://en.wikipedia.org/wiki/Roman_numerals
|
||||||
|
@ -31,7 +31,7 @@ def roman_to_int(roman: str) -> int:
|
||||||
total += vals[roman[i]]
|
total += vals[roman[i]]
|
||||||
i += 1
|
i += 1
|
||||||
return total
|
return total
|
||||||
def int_to_roman(number: int) -> str:
|
def int_to_roman(number: int) -> str:
|
||||||
"""
|
"""
|
||||||
Convert an integer to a Roman numeral, supporting Vinculum notation (underscore _ represents 1000 times).
|
Convert an integer to a Roman numeral, supporting Vinculum notation (underscore _ represents 1000 times).
|
||||||
Given a integer, convert it to an roman numeral.
|
Given a integer, convert it to an roman numeral.
|
||||||
|
@ -48,7 +48,7 @@ def roman_to_int(roman: str) -> int:
|
||||||
factor, number = divmod(number, arabic)
|
factor, number = divmod(number, arabic)
|
||||||
result.append(roman * factor)
|
result.append(roman * factor)
|
||||||
if number == 0:
|
if number == 0:
|
||||||
reak
|
break
|
||||||
return "".join(result)
|
return "".join(result)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user