Roman To Integer
String Math
Problem
Given a roman numeral, convert it to an integer.
For example:
Thought Process
We can use a dictionary to map the corresponding roman numerals to their numbers
To handle the case where a smaller roman numeral is placed before a larger one (which results in a subtraction), we need to subtract the previous number twice
Need to subtract twice because we are taking that number away from the count (which we added to it before) and then we subtract again because of the normal roman numeral rule where you subtract the lesser number from the higher one.
Solution
Key Points
For the current roman numeral, if the previous roman numeral is of a lesser number then we have to subtract the previous roman numeral twice from the count
Time Complexity
Time:
Space:
Last updated
Was this helpful?