Roman numerals write numbers with seven letters, each worth a fixed amount:
I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000.
A numeral is normally read by adding up its letters, which run from the largest value to the smallest: CLX is 100 + 50 + 10 = 160. The exception is six fixed pairs where a smaller letter stands in front of a larger one. Then the smaller one is taken away instead of added:
IV = 4 and IX = 9XL = 40 and XC = 90CD = 400 and CM = 900Given the numeral s, return the whole number it stands for.
V is 5, and each of the three Is after it adds 1.
X comes before the larger L, so together they make 40. The two Is add 2.
MM is 2000, CD is 400, XC is 90 and IV is 4.
Constraints
1 <= s.length <= 15s uses only the letters I, V, X, L, C, D and M.s is the standard way of writing a whole number from 1 to 3999: largest values first, with subtraction only through the six pairs above. Forms like IIII, VX or IC never appear.Each letter is added, except when a smaller letter sits right before a larger one: then it is subtracted.
8