Convert a Roman numeral string to its integer value. Roman numerals use seven symbols: I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Normally, symbols are arranged from largest to smallest, but when a smaller symbol appears before a larger one, subtract the smaller value (e.g., IV=4, IX=9, XL=40, XC=90, CD=400, CM=900). Return null for null input and 0 for empty string.

Examples:

Input: roman = 'III' Output: 3 Explanation: I + I + I = 1 + 1 + 1 = 3 Input: roman = 'LVIII' Output: 58 Explanation: L + V + I + I + I = 50 + 5 + 1 + 1 + 1 = 58 Input: roman = 'MCMXCIV' Output: 1994 Explanation: M + CM + XC + IV = 1000 + 900 + 90 + 4 = 1994 Input: roman = null Output: null Explanation: Null input returns null
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay May 2026

Contest runs May 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In