mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 02:41:42 +08:00
批量更新数据
This commit is contained in:
@@ -1,51 +1,104 @@
|
||||
<p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
|
||||
<p>Seven different symbols represent Roman numerals with the following values:</p>
|
||||
|
||||
<pre>
|
||||
<strong>Symbol</strong> <strong>Value</strong>
|
||||
I 1
|
||||
V 5
|
||||
X 10
|
||||
L 50
|
||||
C 100
|
||||
D 500
|
||||
M 1000</pre>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Symbol</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>I</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>V</td>
|
||||
<td>5</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>X</td>
|
||||
<td>10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>L</td>
|
||||
<td>50</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>C</td>
|
||||
<td>100</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>D</td>
|
||||
<td>500</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>M</td>
|
||||
<td>1000</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p>For example, <code>2</code> is written as <code>II</code> in Roman numeral, just two one's added together. <code>12</code> is written as <code>XII</code>, which is simply <code>X + II</code>. The number <code>27</code> is written as <code>XXVII</code>, which is <code>XX + V + II</code>.</p>
|
||||
|
||||
<p>Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not <code>IIII</code>. Instead, the number four is written as <code>IV</code>. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as <code>IX</code>. There are six instances where subtraction is used:</p>
|
||||
<p>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:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>I</code> can be placed before <code>V</code> (5) and <code>X</code> (10) to make 4 and 9. </li>
|
||||
<li><code>X</code> can be placed before <code>L</code> (50) and <code>C</code> (100) to make 40 and 90. </li>
|
||||
<li><code>C</code> can be placed before <code>D</code> (500) and <code>M</code> (1000) to make 400 and 900.</li>
|
||||
<li>If the value does not start with 4 or 9, select the symbol of the maximal value that can be subtracted from the input, append that symbol to the result, subtract its value, and convert the remainder to a Roman numeral.</li>
|
||||
<li>If the value starts with 4 or 9 use the <strong>subtractive form</strong> representing one symbol subtracted from the following symbol, for example, 4 is 1 (<code>I</code>) less than 5 (<code>V</code>): <code>IV</code> and 9 is 1 (<code>I</code>) less than 10 (<code>X</code>): <code>IX</code>. Only the following subtractive forms are used: 4 (<code>IV</code>), 9 (<code>IX</code>), 40 (<code>XL</code>), 90 (<code>XC</code>), 400 (<code>CD</code>) and 900 (<code>CM</code>).</li>
|
||||
<li>Only powers of 10 (<code>I</code>, <code>X</code>, <code>C</code>, <code>M</code>) can be appended consecutively at most 3 times to represent multiples of 10. You cannot append 5 (<code>V</code>), 50 (<code>L</code>), or 500 (<code>D</code>) multiple times. If you need to append a symbol 4 times use the <strong>subtractive form</strong>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Given an integer, convert it to a roman numeral.</p>
|
||||
<p>Given an integer, convert it to a Roman numeral.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">num = 3749</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"MMMDCCXLIX"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 3
|
||||
<strong>Output:</strong> "III"
|
||||
<strong>Explanation:</strong> 3 is represented as 3 ones.
|
||||
3000 = MMM as 1000 (M) + 1000 (M) + 1000 (M)
|
||||
700 = DCC as 500 (D) + 100 (C) + 100 (C)
|
||||
40 = XL as 10 (X) less of 50 (L)
|
||||
9 = IX as 1 (I) less of 10 (X)
|
||||
Note: 49 is not 1 (I) less of 50 (L) because the conversion is based on decimal places
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">num = 58</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"LVIII"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 58
|
||||
<strong>Output:</strong> "LVIII"
|
||||
<strong>Explanation:</strong> L = 50, V = 5, III = 3.
|
||||
50 = L
|
||||
8 = VIII
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">num = 1994</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"MCMXCIV"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 1994
|
||||
<strong>Output:</strong> "MCMXCIV"
|
||||
<strong>Explanation:</strong> M = 1000, CM = 900, XC = 90 and IV = 4.
|
||||
1000 = M
|
||||
900 = CM
|
||||
90 = XC
|
||||
4 = IV
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
Reference in New Issue
Block a user