Roman to Integer
Problem statement
Given the canonical uppercase Roman-numeral representation of an integer from 1 through 3999, return its integer value.
The subtractive pairs are IV, IX, XL, XC, CD, and CM.
Function
romanToInteger(roman: String) → intExamples
Example 1
roman = "III"return = 3The signed local contribution of each symbol reproduces canonical additive and subtractive notation.
Example 2
roman = "IV"return = 4The signed local contribution of each symbol reproduces canonical additive and subtractive notation.
Example 3
roman = "IX"return = 9The signed local contribution of each symbol reproduces canonical additive and subtractive notation.
Constraints
1 <= roman.length <= 15.romanis the canonical uppercase representation of a value from 1 through 3999.