Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Roman to Integer

Easy

Topics
Hash TableMathString

Given a Roman numeral string s, convert it to an integer. Symbols: I=1, V=5, X=10, L=50, C=100, D=500, M=1000. A smaller symbol before a larger one is subtracted (e.g., IV = 4).

Example 1

Input:  s = "III"
Output: 3

Example 2

Input:  s = "LVIII"
Output: 58

Example 3

Input:  s = "MCMXCIV"
Output: 1994

Constraints

  • 1 <= s.length <= 15
  • s is a valid Roman numeral in the range [1, 3999].
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access