Asked 1 month ago
1
62
Seven different symbols represent Roman numerals with the following values:
Symbol | Value |
---|---|
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1000 |
Roman numerals are formed by appending the conversions of decimal place values from highest to lowest. Converting a decimal place value into a Roman numeral has the following rules:
I
) less than 5 (V
):Â IV
 and 9 is 1 (I
) less than 10 (X
):Â IX
. Only the following subtractive forms are used: 4 (IV
), 9 (IX
), 40 (XL
), 90 (XC
), 400 (CD
) and 900 (CM
).I
, X
, C
, M
) can be appended consecutively at most 3 times to represent multiples of 10. You cannot append 5Â (V
), 50 (L
), or 500 (D
) multiple times. If you need to append a symbol 4 times use the subtractive form.Given an integer, convert it to a Roman numeral.
Example 1:
Input:Â num = 3749
Output:Â "MMMDCCXLIX"
Explanation:
Example 2:
Input:Â num = 58
Output:Â "LVIII"
Explanation:
Example 3:
Input:Â num = 1994
Output:Â "MCMXCIV"
Explanation:
Â
Constraints:
1 <= num <= 3999
1
0
0
This is my approach:
They said this is medium type question in LeetCode but for me which is easy for me since this question is one of the certificate lessons from freeCodeCamp's Javascript Algorithms and Data Structures Course
. I feel easy maybe I have familiar before. But anyway for me Roman to Integer
is more difficult. What do yall think?