Roman Number to Integer
Easy Acceptance 43.21% Points 20.00
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
Examples
Example 1
Example 1
Input: s = "CDXLIV"
Output: 444
Explanation: CD = 400, XL = 40, IV = 4 ? Total = 400 + 40 + 4 = 444
Example 2
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
Hints
Hint 1
Expected Time Complexity: O(n)
Hint 2
Expected Space Complexity: O(1)
Constraints
- 1<= roman number <=3999
- s[i] belongs to [I, V, X, L, C, D, M]
Companies
Amazon Microsoft Zoho
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.