Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def roman_to_int(roman_number: str) -> int:
- d_one = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
- #d_two = {"IV": 4, "IX": 9, "XL": 40, "XC": 90, "CD": 400, "CM": 900}
- res = 0
- ind = 0
- """while ind < len(roman_number):
- num = roman_number[ind: ind + 2]
- if num in d_two:
- res += d_two[num]
- continue
- res += d_one[roman_number[ind]]
- ind += 1
- return res"""
- for i in range(len(roman_number) - 1):
- if d_one[roman_number[i]] < d_one[roman_number[i+1]]:
- res -= d_one[roman_number[i]]
- else:
- res += d_one[roman_number[i]]
- res += d_one[roman_number[-1]]
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement