Problem
Convert a Roman numeral to an integer. The symbols are I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000. Symbols are usually written largest to smallest and added up, but a smaller symbol placed before a larger one is subtracted (IV is 4, IX is 9, XL is 40, CM is 900).
Example 1
- Input
- s = "III"
- Output
- 3
Example 2
- Input
- s = "LVIII"
- Output
- 58
- Why
- L + V + III
Example 3
- Input
- s = "MCMXCIV"
- Output
- 1994
- Why
- M + CM + XC + IV
Constraints
1 <= s.length <= 15s contains only the characters I, V, X, L, C, D, M.s is a valid Roman numeral in the range [1, 3999].