Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe4f370

Browse files
committed
Added README.md file for Roman to Integer
1 parent 7fb8d0c commit fe4f370

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

‎13-roman-to-integer/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<h2><a href="https://leetcode.com/problems/roman-to-integer">Roman to Integer</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>Roman numerals are represented by seven different symbols:&nbsp;<code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
2+
3+
<pre>
4+
<strong>Symbol</strong> <strong>Value</strong>
5+
I 1
6+
V 5
7+
X 10
8+
L 50
9+
C 100
10+
D 500
11+
M 1000</pre>
12+
13+
<p>For example,&nbsp;<code>2</code> is written as <code>II</code>&nbsp;in Roman numeral, just two ones added together. <code>12</code> is written as&nbsp;<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>
14+
15+
<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>
16+
17+
<ul>
18+
<li><code>I</code> can be placed before <code>V</code> (5) and <code>X</code> (10) to make 4 and 9.&nbsp;</li>
19+
<li><code>X</code> can be placed before <code>L</code> (50) and <code>C</code> (100) to make 40 and 90.&nbsp;</li>
20+
<li><code>C</code> can be placed before <code>D</code> (500) and <code>M</code> (1000) to make 400 and 900.</li>
21+
</ul>
22+
23+
<p>Given a roman numeral, convert it to an integer.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong class="example">Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> s = &quot;III&quot;
30+
<strong>Output:</strong> 3
31+
<strong>Explanation:</strong> III = 3.
32+
</pre>
33+
34+
<p><strong class="example">Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> s = &quot;LVIII&quot;
38+
<strong>Output:</strong> 58
39+
<strong>Explanation:</strong> L = 50, V= 5, III = 3.
40+
</pre>
41+
42+
<p><strong class="example">Example 3:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> s = &quot;MCMXCIV&quot;
46+
<strong>Output:</strong> 1994
47+
<strong>Explanation:</strong> M = 1000, CM = 900, XC = 90 and IV = 4.
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= s.length &lt;= 15</code></li>
55+
<li><code>s</code> contains only&nbsp;the characters <code>(&#39;I&#39;, &#39;V&#39;, &#39;X&#39;, &#39;L&#39;, &#39;C&#39;, &#39;D&#39;, &#39;M&#39;)</code>.</li>
56+
<li>It is <strong>guaranteed</strong>&nbsp;that <code>s</code> is a valid roman numeral in the range <code>[1, 3999]</code>.</li>
57+
</ul>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /