Search⌘ K
AI Features

Solution: Roman to Integer

Explore how to convert Roman numerals into integer values by applying a hash map lookup for both single and subtractive numeral pairs. Learn to traverse the numeral string efficiently while handling unique cases like IV and IX through a clear step-by-step algorithm. By the end, you will understand a clean method to map Roman symbols to integers using constant space and linear time complexity.

Statement

Given a string, s, representing a Roman numeral, return the integer value of the Roman numeral.

Seven different symbols represent Roman numerals:

Symbol

Value

I

1

V

5

X

10

L

50

C

100

D

500

M

1000

So, in Roman numerals, 22 is written as II\text {II}, which is simply two ...