132. Roman to Integer
Easy · String
Given a Roman numeral string, convert it to an integer.
Roman numerals are represented by seven different symbols: I (1), V (5), X (10), L (50), C (100), D (500), M (1000). These symbols can be combined to form larger numbers. In most cases, symbols are written from largest to smallest, left to right. However, there are subtractive cases: I can be placed before V (5) and X (10) to make 4 and 9; X can be placed before L (50) and C (100) to make 40 and 90; C can be placed before D (500) and M (1000) to make 400 and 900.
Examples
Example 1 Input: "III" Output: 3 Explanation: III = 1 + 1 + 1 = 3
Example 2 Input: "MCMXCIV" Output: 1994 Explanation: M = 1000, CM = 900, XC = 90, IV = 4. Total: 1000 + 900 + 90 + 4 = 1994
Constraints
- Standard input/output constraints apply