Loading...
Loading...
Loading...
Roman numerals are represented by seven symbols: I, V, X, L, C, D, M with values 1, 5, 10, 50, 100, 500, 1000.
Numerals are usually written largest→smallest left to right, but six subtractive cases apply:
IV = 4, IX = 9XL = 40, XC = 90CD = 400, CM = 900Given a Roman numeral string, convert it to an integer.
Input: String s.
Output: Integer value.
Input: s = "III" → Output: 3
Input: s = "LVIII" → Output: 58 (L=50, V=5, III=3)
Input: s = "MCMXCIV" → Output: 1994 (M=1000, CM=900, XC=90, IV=4)
s[i] to s[i+1]. If smaller, subtract; else add.{I:1, V:5, X:10, L:50, C:100, D:500, M:1000}.1 <= s.length <= 15 s contains only the chars I, V, X, L, C, D, M s represents a valid roman numeral in [1, 3999]