Practice Roman to Integer
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Convert a valid Roman numeral into its integer value. Symbol values are I=1, V=5, X=10, L=50, C=100, D=500, and M=1000. Usually values are added. The subtractive pairs IV, IX, XL, XC, CD, and CM instead represent 4, 9, 40, 90, 400, and 900. Practice approach: Scan left to right. Subtract a symbol when the following symbol has a larger value; otherwise add it. The input is guaranteed valid, so this covers the allowed subtractive pairs. Runtime is O(n) with constant extra storage.
Source: Roman to Integer on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "III"
3
# Example 2
s = "LVIII"
58
# Example 3
s = "MCMXCIV"
1994
Constraints
Related LeetCode Problems
Practice more problems similar to Roman to Integer.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.