Convert a valid canonical Roman numeral to an integer. A smaller symbol before a larger symbol is subtractive; otherwise values are added.
Input / output
s: stringExamples
"III" returns 3."MCMXCVI" returns 1996.Constraints
1 <= s.length <= 15s is a valid uppercase canonical Roman numeral representing 1..3999.Follow-up Can you express the conversion as a single left-to-right pass without special-casing each subtractive pair?