Roman to Integer

Given a Roman numeral string s, convert it to an integer. The key idea is to extract symbol values and apply subtractive notation correctly.

Input Format

s = Roman numeral string

Output Format

integer value of the Roman numeral

Constraints

  • 1 <= s.length <= 15

Examples

Example 1:

Input:

s = "III"

Output:

3

Explanation:

III = 1 + 1 + 1 = 3.

Example 2:

Input:

s = "MCMXCIV"

Output:

1994

Explanation:

MCMXCIV = 1000 + 900 + 90 + 4 = 1994.

Loading...
Roman to Integer - Math DSA Problem