PIXELBANKv9.1.0
Menu

Convert a Roman numeral string to an integer.

I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Subtractive: IV=4, IX=9, XL=40, XC=90, CD=400, CM=900.

Example:

Input:
III
Output:
3
Reasoning:
  • The input string III is analyzed from left to right to determine the integer equivalent of each Roman numeral.
  • Since each I has a value of 11 and there are no subtractive cases in the input, we simply add the values of the three Is together: 1+1+1=31 + 1 + 1 = 3.
  • The final output is the sum calculated in the previous step, which is 33.

Constraints:

  • 1 <= len(s) <= 15
  • s is a valid Roman numeral in [1, 3999]
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Roman to Integer - Easy | PixelBank