Convert Roman Number to Decimal (Integer) | Write Python Program to Convert Roman to Integer
In this tutorial, we will write the Python program to convert the Roman numbers into the integer. It is a popular problem was asked by the tech giant Amazon, Facebook in the interview. Let's see the problem statement and implementation of the solution.
A roman number is given as a string; the task is to convert the corresponding integer value. The symbols are given below for reference.
Input:s = VI
Input: XOutput: 10XL is a Roman symbol which represents 40
Let's implement the algorithm to the Python program.
In the above code, we define a rom_value() function which returns corresponding to the symbol. Next we define the romanTointeger() method which converts the value roman value to integer. In the romanToInteger() method,
Time Complexity: O(n), where n is the length of the string. Only one traversal of the string is required.
Space Complexity: O(1). As no extra space is required
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week