Roman to Number Leetcode

#roman, #number, #leetcode, #numeral.

Hello, this is my first log to my website. I hope we can learn something new from my website in the future. In this Log, I’m gonna show you a cool feature I encounter when solving the Leet Code problem. So, Roman to Number is a number system that turns any Roman numerals into numbers, for example, MMXXIII is the roman numeral for the year 2023, and MMI for the year 2001.

Roman numerals represent a number system that was widely used throughout Europe as the standard writing system until the middle ages. Modern Roman numerals use seven letters to represent different numbers. There are I, V, X, L, C, D, and M, I value is 1, the V value is 5, the X value is 10, the L value is 50, the C value is 100, the D value is 500, and M value is 1000. A Rule is applied, the bigger letter is used first in the letter naming, for example, M is used first before D then C then L, and so on (MDLXVI is 1566). Another rule is if a letter (lower value) is used before the bigger letter for example IV, XIX, XL, and CD. it means the value for the bigger letter is being subtracted by the lower letter, so IV is 5 - 1 = 4, XIX, is 10 + (10 – 1) = 19, XL is 50 – 10 = 40, and CD is 500 – 100 = 400. For the last example, the current year is MMXXIII, we can calculate the number as 1000 + 1000 + 10 + 10 + 3 = 2023. Here you can try to process any Roman numeral into a number.

Cheers :D!!

Number

Roman