LeetCode / Roman to Integer
Problem
- Link
- Description
- Convert Roman numerals to Arabic numerals
- Type
- Brute Force
Solution 1
| |
- Description
- Check if the string matches in order: M/1000, CM/900, D/500, CD/400, C/100, XC/90, L/50, XL/40, X/10, IX/9, V/5, IV/4, I/1
- If the string matches, remove the matched string and add the corresponding value to the result
- Time Complexity
- O(len(s))
- For loop of size len(s)
- Space Complexity
- O(len(s))
- Memory usage proportional to len(s) for function input
Solution 2
| |
- Description
- Same approach as “Solution 1” but uses a mapping array