Roman numerals use seven symbols: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000.
Symbols are normally written from the biggest to the smallest, and their values are added. But when a smaller symbol comes right before a bigger one, its value is taken away instead. This happens in six cases: IV (4), IX (9), XL (40), XC (90), CD (400) and CM (900).
Given a Roman numeral s, return its value as an integer.
Examples
Example 1:
Input: s = "XIV"
Output: 14
Explanation: X = 10 and IV = 4.
Example 2:
Input: s = "MMXXIV"
Output: 2024
Explanation: MM = 2000, XX = 20 and IV = 4.
Example 3:
Input: s = "CMXCIX"
Output: 999
Explanation: CM = 900, XC = 90 and IX = 9.