Roman number to Integer
- Shreyas Naphad
- Jun 17, 2024
- 1 min read
In this article, we will solve the problem of converting a Roman numeral to an integer.
Problem Statement:
Given a Roman numeral, convert it to an integer. The Roman numeral system uses the following symbols and their respective values:
Example 1:
Input: s = "III"
Output: 3
Example 2:
Input: s = "IV"
Output: 4
Solution:
To convert a Roman numeral to an integer, follow these steps:
1. Create a map of Roman numerals to their corresponding integer values.
2. Iterate through the given Roman numeral string.
3. If the current numeral value is less than the next numeral value, subtract it from the result.
4. Otherwise, add it to the result.
Time Complexity: O(N)
Space Complexity: O(1)





Comments