Given a string in Roman number format (s), your task is to convert it to an integer. Various symbols and their values are given below.
Note: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000
Example 1
Input: s = "CDXLIV"
Output: 444
Explanation: CD = 400, XL = 40, IV = 4 ? Total = 400 + 40 + 4 = 444
Example 2
Input: s = "DCCCXC"
Output: 890
Explanation: D = 500, C = 100, C = 100, C = 100, XC = 90 ? Total = 500 + 100 + 100 + 100 + 90 = 890
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
CDXLIV
444
DCCCXC
890