#155EasyStrings· Parsing with Lookahead
Roman Numeral Reader
Input format
`s`: a valid roman numeral made of the characters I, V, X, L, C, D and M.
Output format
An integer between 1 and 3999.
Examples
Input: s = "III"
Output: 3
Three ones add up to 3.
Input: s = "LVIII"
Output: 58
L = 50, V = 5 and III = 3, so 50 + 5 + 3 = 58.
Input: s = "MCMXCIV"
Output: 1994
M = 1000, CM = 900, XC = 90, IV = 4, which adds up to 1994.
Constraints
- 1 <= s.length <= 15
- s is a valid roman numeral in the range [1, 3999].
Study first
- #strings
- #hash-table
- #math
- #parsing