easy - accepted / - tried
Roman numerals are represented by combinations of following seven symbols, each with a fixed integer value.
For Standard form, subtractive notation is used, meaning 4 is
IV rather than
IIII, 9 is
IX rather than
VIIII. Same rule applies to 40(
XL) and 900(
Simply speaking, the roman numerals in standard form follow these rules.
- symbols are listed from highest to lowest, from left to right
- from left to right, if the next symbol value is bigger than current one, it means subtracting, otherwise adding.
romanToInteger(). The input are all valid strings.
romanToInteger('CXXIII') // 123 romanToInteger('MCMXCIX') // 1999 romanToInteger('MMMCDXX') // 3420
Let's try to solve this problem within 10 mintues.