Given a string s representing a Roman numeral, convert it to an integer.
Roman numeral symbols and their values:
| Symbol | Value | |--------|-------| | I | 1 | | V | 5 | | X | 10 | | L | 50 | | C | 100 | | D | 500 | | M | 1000 |
Roman numerals are usually written largest to smallest from left to right. However, there are six subtractive cases:
IV = 4, IX = 9XL = 40, XC = 90CD = 400, CM = 900When a smaller value appears before a larger value, it is subtracted instead of added.
s = "III"3s = "LVIII"58s = "MCMXCIV"19941 <= s.length <= 15s contains only the characters I, V, X, L, C, D, Ms is a valid Roman numeral in the range [1, 3999]Run your code to see results
Use Cmd+Enter to run