You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
6
+
7
+
Symbol Value
8
+
I 1
9
+
V 5
10
+
X 10
11
+
L 50
12
+
C 100
13
+
D 500
14
+
M 1000
15
+
16
+
For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
17
+
18
+
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
19
+
20
+
*`I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
21
+
*`X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
22
+
*`C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
23
+
24
+
Given an integer, convert it to a roman numeral.
25
+
26
+
**Example 1:**
27
+
28
+
**Input:** num = 3
29
+
30
+
**Output:** "III"
31
+
32
+
**Example 2:**
33
+
34
+
**Input:** num = 4
35
+
36
+
**Output:** "IV"
37
+
38
+
**Example 3:**
39
+
40
+
**Input:** num = 9
41
+
42
+
**Output:** "IX"
43
+
44
+
**Example 4:**
45
+
46
+
**Input:** num = 58
47
+
48
+
**Output:** "LVIII"
49
+
50
+
**Explanation:** L = 50, V = 5, III = 3.
51
+
52
+
**Example 5:**
53
+
54
+
**Input:** num = 1994
55
+
56
+
**Output:** "MCMXCIV"
57
+
58
+
**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4.
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
6
+
7
+
Symbol Value
8
+
I 1
9
+
V 5
10
+
X 10
11
+
L 50
12
+
C 100
13
+
D 500
14
+
M 1000
15
+
16
+
For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
17
+
18
+
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
19
+
20
+
*`I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
21
+
*`X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
22
+
*`C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
23
+
24
+
Given a roman numeral, convert it to an integer.
25
+
26
+
**Example 1:**
27
+
28
+
**Input:** s = "III"
29
+
30
+
**Output:** 3
31
+
32
+
**Example 2:**
33
+
34
+
**Input:** s = "IV"
35
+
36
+
**Output:** 4
37
+
38
+
**Example 3:**
39
+
40
+
**Input:** s = "IX"
41
+
42
+
**Output:** 9
43
+
44
+
**Example 4:**
45
+
46
+
**Input:** s = "LVIII"
47
+
48
+
**Output:** 58
49
+
50
+
**Explanation:** L = 50, V= 5, III = 3.
51
+
52
+
**Example 5:**
53
+
54
+
**Input:** s = "MCMXCIV"
55
+
56
+
**Output:** 1994
57
+
58
+
**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4.
59
+
60
+
**Constraints:**
61
+
62
+
*`1 <= s.length <= 15`
63
+
*`s` contains only the characters `('I', 'V', 'X', 'L', 'C', 'D', 'M')`.
64
+
* It is **guaranteed** that `s` is a valid roman numeral in the range `[1, 3999]`.
0 commit comments