Search⌘ K
AI Features

Roman Numerals to Integers

Understand how to convert Roman numerals to integers by applying string traversal and subtraction rules. This lesson teaches you to iterate through Roman numeral strings, handle special cases, and efficiently compute integer values with a clear step-by-step approach.

Statement

Given a Roman numeral, our task is to convert it to an integer.

Roman numerals are represented by seven different symbols:

“I”, “V”, “X”, “L”, “C”, “D”, and “M”.

Symbol

Value

I

1

V

5

X

10

L

50

C

100

D

500

M

1000

Roman numerals are traditionally written from left to right, from largest to smallest.

  • However, the numeral for four is “IV” instead of “IIII”. We deduct the one because it is less than five, resulting in four.
  • The number nine, written as “IX,” follows the same pattern.

This subtraction rule occurs in six different situations:

  • “I” can be placed before “V” (5) and “X” (10) to make four and nine, respectively.
  • “X” can be placed before “L” (50) and “C” (100) to make 40 and 90,
...