Skip to content

Commit d14c5d9

Browse files
authored
feat: update lc problems (doocs#2834)
1 parent a9aad79 commit d14c5d9

File tree

77 files changed

+623
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+623
-519
lines changed

solution/0000-0099/0002.Add Two Numbers/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,43 @@ tags:
1818

1919
<!-- description:start -->
2020

21-
<p>给你两个 <strong>非空</strong> 的链表,表示两个非负的整数。它们每位数字都是按照 <strong>逆序</strong> 的方式存储的,并且每个节点只能存储 <strong>一位</strong> 数字。</p>
21+
<p>给你两个&nbsp;<strong>非空</strong> 的链表,表示两个非负的整数。它们每位数字都是按照&nbsp;<strong>逆序</strong>&nbsp;的方式存储的,并且每个节点只能存储&nbsp;<strong>一位</strong>&nbsp;数字。</p>
2222

2323
<p>请你将两个数相加,并以相同形式返回一个表示和的链表。</p>
2424

25-
<p>你可以假设除了数字 0 之外,这两个数都不会以 0 开头。</p>
25+
<p>你可以假设除了数字 0 之外,这两个数都不会以 0&nbsp;开头。</p>
2626

27-
<p> </p>
27+
<p>&nbsp;</p>
2828

29-
<p><strong>示例 1:</strong></p>
29+
<p><strong class="example">示例 1:</strong></p>
3030
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0002.Add%20Two%20Numbers/images/addtwonumber1.jpg" style="width: 483px; height: 342px;" />
3131
<pre>
3232
<strong>输入:</strong>l1 = [2,4,3], l2 = [5,6,4]
3333
<strong>输出:</strong>[7,0,8]
3434
<strong>解释:</strong>342 + 465 = 807.
3535
</pre>
3636

37-
<p><strong>示例 2:</strong></p>
37+
<p><strong class="example">示例 2:</strong></p>
3838

3939
<pre>
4040
<strong>输入:</strong>l1 = [0], l2 = [0]
4141
<strong>输出:</strong>[0]
4242
</pre>
4343

44-
<p><strong>示例 3:</strong></p>
44+
<p><strong class="example">示例 3:</strong></p>
4545

4646
<pre>
4747
<strong>输入:</strong>l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
4848
<strong>输出:</strong>[8,9,9,9,0,0,0,1]
4949
</pre>
5050

51-
<p> </p>
51+
<p>&nbsp;</p>
5252

5353
<p><strong>提示:</strong></p>
5454

5555
<ul>
5656
<li>每个链表中的节点数在范围 <code>[1, 100]</code> 内</li>
57-
<li><code>0 <= Node.val <= 9</code></li>
57+
<li><code>0 &lt;= Node.val &lt;= 9</code></li>
5858
<li>题目数据保证列表表示的数字不含前导零</li>
5959
</ul>
6060

solution/0000-0099/0005.Longest Palindromic Substring/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ tags:
1818

1919
<!-- description:start -->
2020

21-
<p>给你一个字符串 <code>s</code>,找到 <code>s</code> 中最长的回文<span data-keyword="substring">子串</span>。</p>
22-
23-
<p>如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。</p>
21+
<p>给你一个字符串 <code>s</code>,找到 <code>s</code> 中最长的 <span data-keyword="palindromic-string">回文</span> <span data-keyword="substring-nonempty">子串</span>。</p>
2422

2523
<p>&nbsp;</p>
2624

solution/0000-0099/0012.Integer to Roman/README.md

+85-41
Original file line numberDiff line numberDiff line change
@@ -18,71 +18,115 @@ tags:
1818

1919
<!-- description:start -->
2020

21-
<p>罗马数字包含以下七种字符: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>,<code>C</code>,<code>D</code> 和 <code>M</code>。</p>
22-
23-
<pre>
24-
<strong>字符</strong> <strong>数值</strong>
25-
I 1
26-
V 5
27-
X 10
28-
L 50
29-
C 100
30-
D 500
31-
M 1000</pre>
32-
33-
<p>例如, 罗马数字 2 写做 <code>II</code> ,即为两个并列的 1。12 写做 <code>XII</code> ,即为 <code>X</code> + <code>II</code> 。 27 写做  <code>XXVII</code>, 即为 <code>XX</code> + <code>V</code> + <code>II</code> 。</p>
34-
35-
<p>通常情况下,罗马数字中小的数字在大的数字的右边。但也存在特例,例如 4 不写做 <code>IIII</code>,而是 <code>IV</code>。数字 1 在数字 5 的左边,所表示的数等于大数 5 减小数 1 得到的数值 4 。同样地,数字 9 表示为 <code>IX</code>。这个特殊的规则只适用于以下六种情况:</p>
21+
<p>七个不同的符号代表罗马数字,其值如下:</p>
22+
23+
<table>
24+
<thead>
25+
<tr>
26+
<th>符号</th>
27+
<th>值</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<tr>
32+
<td>I</td>
33+
<td>1</td>
34+
</tr>
35+
<tr>
36+
<td>V</td>
37+
<td>5</td>
38+
</tr>
39+
<tr>
40+
<td>X</td>
41+
<td>10</td>
42+
</tr>
43+
<tr>
44+
<td>L</td>
45+
<td>50</td>
46+
</tr>
47+
<tr>
48+
<td>C</td>
49+
<td>100</td>
50+
</tr>
51+
<tr>
52+
<td>D</td>
53+
<td>500</td>
54+
</tr>
55+
<tr>
56+
<td>M</td>
57+
<td>1000</td>
58+
</tr>
59+
</tbody>
60+
</table>
61+
62+
<p>罗马数字是通过添加从最高到最低的小数位值的转换而形成的。将小数位值转换为罗马数字有以下规则:</p>
3663

3764
<ul>
38-
<li><code>I</code> 可以放在 <code>V</code> (5) 和 <code>X</code> (10) 的左边,来表示 4 和 9。</li>
39-
<li><code>X</code> 可以放在 <code>L</code> (50) 和 <code>C</code> (100) 的左边,来表示 40 和 90。 </li>
40-
<li><code>C</code> 可以放在 <code>D</code> (500) 和 <code>M</code> (1000) 的左边,来表示 400 和 900。</li>
65+
<li>如果该值不是以 4 或 9 开头,请选择可以从输入中减去的最大值的符号,将该符号附加到结果,减去其值,然后将其余部分转换为罗马数字。</li>
66+
<li>如果该值以 4 或 9 开头,使用 <strong>减法形式</strong>,表示从以下符号中减去一个符号,例如&nbsp;4 是 5 (<code>V</code>) 减 1 (<code>I</code>): <code>IV</code>&nbsp;,9 是 10 (<code>X</code>) 减&nbsp;1 (<code>I</code>):<code>IX</code>。仅使用以下减法形式:4 (<code>IV</code>),9 (<code>IX</code>),40 (<code>XL</code>),90 (<code>XC</code>),400 (<code>CD</code>) 和&nbsp;900 (<code>CM</code>)。</li>
67+
<li>只有 10 的次方(<code>I</code>, <code>X</code>, <code>C</code>, <code>M</code>)最多可以连续附加 3 次以代表 10 的倍数。你不能多次附加&nbsp;5&nbsp;(<code>V</code>),50 (<code>L</code>) 或 500 (<code>D</code>)。如果需要将符号附加4次,请使用 <strong>减法形式</strong>。</li>
4168
</ul>
4269

43-
<p>给你一个整数,将其转为罗马数字。</p>
70+
<p>给定一个整数,将其转换为罗马数字。</p>
4471

45-
<p> </p>
72+
<p>&nbsp;</p>
4673

47-
<p><strong>示例 1:</strong></p>
74+
<p><strong class="example">示例 1:</strong></p>
4875

49-
<pre>
50-
<strong>输入:</strong> num = 3
51-
<strong>输出:</strong> "III"</pre>
76+
<div class="example-block">
77+
<p><strong>输入:</strong><span class="example-io">num = 3749</span></p>
78+
79+
<p><strong>输出:</strong>&nbsp;<span class="example-io">"MMMDCCXLIX"</span></p>
5280

53-
<p><strong>示例 2:</strong></p>
81+
<p><strong>解释:</strong></p>
5482

5583
<pre>
56-
<strong>输入:</strong> num = 4
57-
<strong>输出:</strong> "IV"</pre>
84+
3000 = MMM 由于 1000 (M) + 1000 (M) + 1000 (M)
85+
700 = DCC 由于 500 (D) + 100 (C) + 100 (C)
86+
40 = XL 由于 50 (L) 减 10 (X)
87+
9 = IX 由于 10 (X) 减 1 (I)
88+
注意:49 不是 50 (L) 减 1 (I) 因为转换是基于小数位
89+
</pre>
90+
</div>
5891

59-
<p><strong>示例 3:</strong></p>
92+
<p><strong class="example">示例 2:</strong></p>
6093

61-
<pre>
62-
<strong>输入:</strong> num = 9
63-
<strong>输出:</strong> "IX"</pre>
94+
<div class="example-block">
95+
<p><strong>输入:</strong><span class="example-io">num = 58</span></p>
96+
97+
<p><strong>输出:</strong><span class="example-io">"LVIII"</span></p>
6498

65-
<p><strong>示例 4:</strong></p>
99+
<p><strong>解释:</strong></p>
66100

67101
<pre>
68-
<strong>输入:</strong> num = 58
69-
<strong>输出:</strong> "LVIII"
70-
<strong>解释:</strong> L = 50, V = 5, III = 3.
102+
50 = L
103+
8 = VIII
71104
</pre>
105+
</div>
106+
107+
<p><strong class="example">示例 3:</strong></p>
72108

73-
<p><strong>示例 5:</strong></p>
109+
<div class="example-block">
110+
<p><strong>输入:</strong><span class="example-io">num = 1994</span></p>
111+
112+
<p><strong>输出:</strong><span class="example-io">"MCMXCIV"</span></p>
113+
114+
<p><strong>解释:</strong></p>
74115

75116
<pre>
76-
<strong>输入:</strong> num = 1994
77-
<strong>输出:</strong> "MCMXCIV"
78-
<strong>解释:</strong> M = 1000, CM = 900, XC = 90, IV = 4.</pre>
117+
1000 = M
118+
900 = CM
119+
90 = XC
120+
4 = IV
121+
</pre>
122+
</div>
79123

80-
<p> </p>
124+
<p>&nbsp;</p>
81125

82126
<p><strong>提示:</strong></p>
83127

84128
<ul>
85-
<li><code>1 <= num <= 3999</code></li>
129+
<li><code>1 &lt;= num &lt;= 3999</code></li>
86130
</ul>
87131

88132
<!-- description:end -->

solution/0000-0099/0014.Longest Common Prefix/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ tags:
2323

2424
<p>&nbsp;</p>
2525

26-
<p><strong>示例 1:</strong></p>
26+
<p><strong class="example">示例 1:</strong></p>
2727

2828
<pre>
2929
<strong>输入:</strong>strs = ["flower","flow","flight"]
3030
<strong>输出:</strong>"fl"
3131
</pre>
3232

33-
<p><strong>示例 2:</strong></p>
33+
<p><strong class="example">示例 2:</strong></p>
3434

3535
<pre>
3636
<strong>输入:</strong>strs = ["dog","racecar","car"]

solution/0000-0099/0027.Remove Element/README.md

+27-23
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,53 @@ tags:
1717

1818
<!-- description:start -->
1919

20-
<p>给你一个数组 <code>nums</code><em>&nbsp;</em>和一个值 <code>val</code>,你需要 <strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地</a></strong> 移除所有数值等于&nbsp;<code>val</code><em>&nbsp;</em>的元素,并返回移除后数组的新长度。</p>
20+
<p>给你一个数组 <code>nums</code><em>&nbsp;</em>和一个值 <code>val</code>,你需要 <strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地</a></strong> 移除所有数值等于&nbsp;<code>val</code><em>&nbsp;</em>的元素。元素的顺序可能发生改变。然后返回&nbsp;<code>nums</code>&nbsp;中与&nbsp;<code>val</code>&nbsp;不同的元素的数量。</p>
2121

22-
<p>不要使用额外的数组空间,你必须仅使用 <code>O(1)</code> 额外空间并 <strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地 </a>修改输入数组</strong>。</p>
22+
<p>假设 <code>nums</code> 中不等于 <code>val</code> 的元素数量为 <code>k</code>,要通过此题,您需要执行以下操作:</p>
2323

24-
<p>元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。</p>
24+
<ul>
25+
<li>更改 <code>nums</code> 数组,使 <code>nums</code> 的前 <code>k</code> 个元素包含不等于 <code>val</code> 的元素。<code>nums</code> 的其余元素和 <code>nums</code> 的大小并不重要。</li>
26+
<li>返回 <code>k</code>。</li>
27+
</ul>
2528

26-
<p>&nbsp;</p>
29+
<p><strong>用户评测:</strong></p>
2730

28-
<p><strong>说明:</strong></p>
31+
<p>评测机将使用以下代码测试您的解决方案:</p>
2932

30-
<p>为什么返回数值是整数,但输出的答案是数组呢?</p>
33+
<pre>
34+
int[] nums = [...]; // 输入数组
35+
int val = ...; // 要移除的值
36+
int[] expectedNums = [...]; // 长度正确的预期答案。
37+
// 它以不等于 val 的值排序。
3138

32-
<p>请注意,输入数组是以<strong>「引用」</strong>方式传递的,这意味着在函数里修改输入数组对于调用者是可见的。</p>
39+
int k = removeElement(nums, val); // 调用你的实现
3340

34-
<p>你可以想象内部操作如下:</p>
41+
assert k == expectedNums.length;
42+
sort(nums, 0, k); // 排序 nums 的前 k 个元素
43+
for (int i = 0; i &lt; actualLength; i++) {
44+
assert nums[i] == expectedNums[i];
45+
}</pre>
3546

36-
<pre>
37-
// <strong>nums</strong> 是以“引用”方式传递的。也就是说,不对实参作任何拷贝
38-
int len = removeElement(nums, val);
39-
40-
// 在函数里修改输入数组对于调用者是可见的。
41-
// 根据你的函数返回的长度, 它会打印出数组中<strong> 该长度范围内</strong> 的所有元素。
42-
for (int i = 0; i &lt; len; i++) {
43-
&nbsp; &nbsp; print(nums[i]);
44-
}
45-
</pre>
47+
<p>如果所有的断言都通过,你的解决方案将会 <strong>通过</strong>。</p>
4648

4749
<p>&nbsp;</p>
4850

4951
<p><strong>示例 1:</strong></p>
5052

5153
<pre>
5254
<strong>输入:</strong>nums = [3,2,2,3], val = 3
53-
<strong>输出:</strong>2, nums = [2,2]
54-
<strong>解释:</strong>函数应该返回新的长度 <strong><code>2</code></strong>, 并且 nums<em> </em>中的前两个元素均为 <strong>2</strong>。你不需要考虑数组中超出新长度后面的元素。例如,函数返回的新长度为 2 ,而 nums = [2,2,3,3] 或 nums = [2,2,0,0],也会被视作正确答案
55-
</pre>
55+
<strong>输出:</strong>2, nums = [2,2,_,_]
56+
<strong>解释:</strong>你的函数函数应该返回 k = 2, 并且 nums<em> </em>中的前两个元素均为 2
57+
你在返回的 k 个元素之外留下了什么并不重要(因此它们并不计入评测)。</pre>
5658

5759
<p><strong>示例 2:</strong></p>
5860

5961
<pre>
6062
<strong>输入:</strong>nums = [0,1,2,2,3,0,4,2], val = 2
61-
<strong>输出:</strong>5, nums = [0,1,3,0,4]
62-
<strong>解释:</strong>函数应该返回新的长度 <strong><code>5</code></strong>, 并且 nums 中的前五个元素为 <strong><code>0</code></strong>, <strong><code>1</code></strong>, <strong><code>3</code></strong>, <strong><code>0</code></strong>, <strong><code>4</code></strong>。注意这五个元素可为任意顺序。你不需要考虑数组中超出新长度后面的元素。
63+
<strong>输出:</strong>5, nums = [0,1,4,0,3,_,_,_]
64+
<strong>解释:</strong>你的函数应该返回 k = 5,并且 nums 中的前五个元素为 0,0,1,3,4。
65+
注意这五个元素可以任意顺序返回。
66+
你在返回的 k 个元素之外留下了什么并不重要(因此它们并不计入评测)。
6367
</pre>
6468

6569
<p>&nbsp;</p>

0 commit comments

Comments
 (0)