Roman to Integer

Roman numerals are represented by seven symbols: I, V, X, L, C, D, and M, with values of 1, 5, 10, 50, 100, 500, and 1000 respectively. They are usually ordered from largest to smallest. However, some numerals like IV and IX use subtraction. Given a Roman numeral, convert it to an integer.

Constraints

  • 1 <= s.length <= 15
  • s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M')
  • It is guaranteed that s is a valid roman numeral in the range [1, 3999].
Saving… · 2 lines
class Solution:
def romanToInteger(self, s: str) -> int:
Console

Click Run to execute sample tests.