Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Roman Number to Integer

Easy Acceptance 43.21% Points 20

Given a string in Roman number format (s), your task is to convert it to an integer. Various symbols and their values are given below.

Note: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000

Examples
Example 1

Example 1

Input: s = "CDXLIV"

Output: 444

Explanation: CD = 400, XL = 40, IV = 4 ? Total = 400 + 40 + 4 = 444

Example 2

Example 2

Input: s = "DCCCXC"

Output: 890

Explanation: D = 500, C = 100, C = 100, C = 100, XC = 90 ? Total = 500 + 100 + 100 + 100 + 90 = 890

Constraints
  • 1<= roman number <=3999
  • s[i] belongs to [I, V, X, L, C, D, M]
Hints
  • Expected Time Complexity: O(n)
  • Expected Space Complexity: O(1)
Topics
String
Companies
Amazon Microsoft Zoho
Added 19 Jul 2026 43.21% acceptance
Ln 1, Col 1Sign in to save your code
CDXLIV
444