Loading...
You are given a valid roman numeral s, built from seven symbols:
| Symbol | Value |
|---|---|
| I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
Symbols are normally written largest to smallest and added up. Six subtractive pairs are the exception: IV (4), IX (9), XL (40), XC (90), CD (400), CM (900). In each of them a smaller symbol before a larger one is subtracted.
Return the integer value of s.
Input: s = "III"
Output: 3
Input: s = "LVIII"
Output: 58
Explanation: L = 50, V = 5, III = 3.
Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90, IV = 4.
s.length ≤15s contains only the characters I, V, X, L, C, D, Ms is guaranteed to be a valid roman numeral in the range [1,3999]Click "Run" to test with sample cases or "Submit" to run all tests.