I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
Letters normally go from largest to smallest and their values add up: XVI = 10 + 5 + 1 = 16. When a smaller letter sits right before a larger one, though, it is subtracted. This happens in exactly six cases:
- IV = 4 and IX = 9,
- XL = 40 and XC = 90,
- CD = 400 and CM = 900.
You are given a string numeral holding a correctly written Roman numeral. Return its value.numeral="XLVII" → 47
XL = 40 (the X before L is subtracted), then V = 5 and II = 2, so 47 in total.
numeral="MMXXIV" → 2024
MM = 2000, XX = 20, IV = 4, which gives 2024.
numeral="CDXC" → 490
numeral contains only the letters I, V, X, L, C, D, Mnumeral is a well-formed Roman numeral for a number from 1 to 3999numeral="XLVII"
47
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.