Skip to content

Commit be22de5

Browse files
committed
chore: update lc problems
1 parent d6e50f1 commit be22de5

File tree

136 files changed

+929
-1393
lines changed

Some content is hidden

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

136 files changed

+929
-1393
lines changed

solution/0000-0099/0064.Minimum Path Sum/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定一个包含非负整数的 <code><em>m</em> x <em>n</em></code> 网格 <code>grid</code> ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。</p>
9+
<p>给定一个包含非负整数的 <code><em>m</em>&nbsp;x&nbsp;<em>n</em></code>&nbsp;网格&nbsp;<code>grid</code> ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。</p>
1010

1111
<p><strong>说明:</strong>每次只能向下或者向右移动一步。</p>
1212

13-
<p> </p>
13+
<p>&nbsp;</p>
1414

15-
<p><strong>示例 1:</strong></p>
15+
<p><strong class="example">示例 1:</strong></p>
1616
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0064.Minimum%20Path%20Sum/images/minpath.jpg" style="width: 242px; height: 242px;" />
1717
<pre>
1818
<strong>输入:</strong>grid = [[1,3,1],[1,5,1],[4,2,1]]
1919
<strong>输出:</strong>7
2020
<strong>解释:</strong>因为路径 1→3→1→1→1 的总和最小。
2121
</pre>
2222

23-
<p><strong>示例 2:</strong></p>
23+
<p><strong class="example">示例 2:</strong></p>
2424

2525
<pre>
2626
<strong>输入:</strong>grid = [[1,2,3],[4,5,6]]
2727
<strong>输出:</strong>12
2828
</pre>
2929

30-
<p> </p>
30+
<p>&nbsp;</p>
3131

3232
<p><strong>提示:</strong></p>
3333

3434
<ul>
3535
<li><code>m == grid.length</code></li>
3636
<li><code>n == grid[i].length</code></li>
37-
<li><code>1 <= m, n <= 200</code></li>
38-
<li><code>0 <= grid[i][j] <= 100</code></li>
37+
<li><code>1 &lt;= m, n &lt;= 200</code></li>
38+
<li><code>0 &lt;= grid[i][j] &lt;= 200</code></li>
3939
</ul>
4040

4141
## 解法

solution/0000-0099/0064.Minimum Path Sum/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<li><code>m == grid.length</code></li>
3232
<li><code>n == grid[i].length</code></li>
3333
<li><code>1 &lt;= m, n &lt;= 200</code></li>
34-
<li><code>0 &lt;= grid[i][j] &lt;= 100</code></li>
34+
<li><code>0 &lt;= grid[i][j] &lt;= 200</code></li>
3535
</ul>
3636

3737
## Solutions

solution/0100-0199/0195.Tenth Line/README_EN.md

-15
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,26 @@
1111
<p>Assume that <code>file.txt</code> has the following content:</p>
1212

1313
<pre>
14-
1514
Line 1
16-
1715
Line 2
18-
1916
Line 3
20-
2117
Line 4
22-
2318
Line 5
24-
2519
Line 6
26-
2720
Line 7
28-
2921
Line 8
30-
3122
Line 9
32-
3323
Line 10
34-
3524
</pre>
3625

3726
<p>Your script should output the tenth line, which is:</p>
3827

3928
<pre>
40-
4129
Line 10
42-
4330
</pre>
4431

4532
<div class="spoilers"><b>Note:</b><br />
46-
4733
1. If the file contains less than 10 lines, what should you output?<br />
48-
4934
2. There&#39;s at least three different solutions. Try to explore all possibilities.</div>
5035

5136
## Solutions

solution/0200-0299/0274.H-Index/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
<p>给你一个整数数组 <code>citations</code> ,其中 <code>citations[i]</code> 表示研究者的第 <code>i</code> 篇论文被引用的次数。计算并返回该研究者的 <strong><code>h</code><em>&nbsp;</em>指数</strong>。</p>
1010

11-
<p>根据维基百科上&nbsp;<a href="https://baike.baidu.com/item/h-index/3991452?fr=aladdin" target="_blank">h 指数的定义</a>:h 代表“高引用次数”,一名科研人员的 <code>h</code><strong>指数</strong>是指他(她)的 (<code>n</code> 篇论文中)<strong>总共</strong>有 <code>h</code> 篇论文分别被引用了<strong>至少</strong> <code>h</code> 次。且其余的 <em><code>n - h</code>&nbsp;</em>篇论文每篇被引用次数&nbsp;<strong>不超过 </strong><em><code>h</code> </em>次。</p>
12-
13-
<p>如果 <code>h</code><em> </em>有多种可能的值,<strong><code>h</code> 指数 </strong>是其中最大的那个。</p>
11+
<p>根据维基百科上&nbsp;<a href="https://baike.baidu.com/item/h-index/3991452?fr=aladdin" target="_blank">h 指数的定义</a>:<code>h</code> 代表“高引用次数” ,一名科研人员的 <code>h</code><strong> 指数 </strong>是指他(她)至少发表了 <code>h</code> 篇论文,并且每篇论文<strong> 至少</strong> 被引用 <code>h</code> 次。如果 <code>h</code><em> </em>有多种可能的值,<strong><code>h</code> 指数 </strong>是其中最大的那个。</p>
1412

1513
<p>&nbsp;</p>
1614

solution/0300-0399/0327.Count of Range Sum/Solution.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
class BinaryIndexedTree {
22
public:
3-
BinaryIndexedTree(int _n) : n(_n), c(_n + 1) {}
3+
BinaryIndexedTree(int _n)
4+
: n(_n)
5+
, c(_n + 1) {}
46

57
void update(int x, int v) {
68
while (x <= n) {

solution/0300-0399/0328.Odd Even Linked List/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Solution {
1414
if (!head) {
1515
return nullptr;
1616
}
17-
ListNode *a = head;
17+
ListNode* a = head;
1818
ListNode *b = head->next, *c = b;
1919
while (b && b->next) {
2020
a->next = b->next;

solution/0300-0399/0329.Longest Increasing Path in a Matrix/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Solution {
102102
this.matrix = matrix;
103103
int ans = 0;
104104
for (int i = 0; i < m; ++i) {
105-
for (int j = 0;j < n; ++j) {
105+
for (int j = 0; j < n; ++j) {
106106
ans = Math.max(ans, dfs(i, j));
107107
}
108108
}

solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Solution {
8080
this.matrix = matrix;
8181
int ans = 0;
8282
for (int i = 0; i < m; ++i) {
83-
for (int j = 0;j < n; ++j) {
83+
for (int j = 0; j < n; ++j) {
8484
ans = Math.max(ans, dfs(i, j));
8585
}
8686
}

solution/0300-0399/0329.Longest Increasing Path in a Matrix/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public int longestIncreasingPath(int[][] matrix) {
1111
this.matrix = matrix;
1212
int ans = 0;
1313
for (int i = 0; i < m; ++i) {
14-
for (int j = 0;j < n; ++j) {
14+
for (int j = 0; j < n; ++j) {
1515
ans = Math.max(ans, dfs(i, j));
1616
}
1717
}

solution/0300-0399/0336.Palindrome Pairs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<strong>输出:</strong>[[0,1],[1,0]]
3333
</pre>
3434

35+
36+
3537
<p><strong>提示:</strong></p>
3638

3739
<ul>

solution/0500-0599/0543.Diameter of Binary Tree/README.md

+23-11
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,37 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。</p>
9+
<p>给你一棵二叉树的根节点,返回该树的 <strong>直径</strong> 。</p>
1010

11-
<p>&nbsp;</p>
11+
<p>二叉树的 <strong>直径</strong> 是指树中任意两个节点之间最长路径的 <strong>长度</strong> 。这条路径可能经过也可能不经过根节点 <code>root</code> 。</p>
12+
13+
<p>两节点之间路径的 <strong>长度</strong> 由它们之间边数表示。</p>
1214

13-
<p><strong>示例 :</strong><br>
14-
给定二叉树</p>
15+
<p>&nbsp;</p>
1516

16-
<pre> 1
17-
/ \
18-
2 3
19-
/ \
20-
4 5
17+
<p><strong class="example">示例 1:</strong></p>
18+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/images/diamtree.jpg" style="width: 292px; height: 302px;" />
19+
<pre>
20+
<strong>输入:</strong>root = [1,2,3,4,5]
21+
<strong>输出:</strong>3
22+
<strong>解释:</strong>3 ,取路径 [4,2,1,3] 或 [5,2,1,3] 的长度。
2123
</pre>
2224

23-
<p>返回&nbsp;<strong>3</strong>, 它的长度是路径 [4,2,1,3] 或者&nbsp;[5,2,1,3]。</p>
25+
<p><strong class="example">示例 2:</strong></p>
26+
27+
<pre>
28+
<strong>输入:</strong>root = [1,2]
29+
<strong>输出:</strong>1
30+
</pre>
2431

2532
<p>&nbsp;</p>
2633

27-
<p><strong>注意:</strong>两结点之间的路径长度是以它们之间边的数目表示。</p>
34+
<p><strong>提示:</strong></p>
35+
36+
<ul>
37+
<li>树中节点数目在范围 <code>[1, 10<sup>4</sup>]</code> 内</li>
38+
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
39+
</ul>
2840

2941
## 解法
3042

solution/0700-0799/0756.Pyramid Transition Matrix/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/images/pyramid2-grid.jpg" style="height: 359px; width: 600px;" /></p>
3838

3939
<pre>
40-
<strong>输入:</strong>bottom = "AABA", allowed = ["AAB","AAC","BCD","BBE","DEF"]
40+
<strong>输入:</strong>bottom = "AAAA", allowed = ["AAB","AAC","BCD","BBE","DEF"]
4141
<strong>输出:</strong>false
4242
<strong>解释:</strong>允许的三角形模式显示在右边。
4343
从最底层(游戏邦注:即第4个关卡)开始,创造第3个关卡有多种方法,但如果尝试所有可能性,你便会在创造第1个关卡前陷入困境。

solution/0700-0799/0799.Champagne Tower/README_EN.md

+2-15
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,35 @@
1515
<p>Now after pouring some non-negative integer cups of champagne, return how full the <code>j<sup>th</sup></code> glass in the <code>i<sup>th</sup></code> row is (both <code>i</code> and <code>j</code> are 0-indexed.)</p>
1616

1717
<p>&nbsp;</p>
18-
1918
<p><strong class="example">Example 1:</strong></p>
2019

2120
<pre>
22-
2321
<strong>Input:</strong> poured = 1, query_row = 1, query_glass = 1
24-
2522
<strong>Output:</strong> 0.00000
26-
2723
<strong>Explanation:</strong> We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.
28-
2924
</pre>
3025

3126
<p><strong class="example">Example 2:</strong></p>
3227

3328
<pre>
34-
3529
<strong>Input:</strong> poured = 2, query_row = 1, query_glass = 1
36-
3730
<strong>Output:</strong> 0.50000
38-
3931
<strong>Explanation:</strong> We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.
40-
4132
</pre>
4233

4334
<p><strong class="example">Example 3:</strong></p>
4435

4536
<pre>
46-
4737
<strong>Input:</strong> poured = 100000009, query_row = 33, query_glass = 17
48-
4938
<strong>Output:</strong> 1.00000
50-
5139
</pre>
5240

5341
<p>&nbsp;</p>
54-
5542
<p><strong>Constraints:</strong></p>
5643

5744
<ul>
58-
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
59-
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>
45+
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
46+
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>
6047
</ul>
6148

6249
## Solutions

solution/0800-0899/0870.Advantage Shuffle/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定两个大小相等的数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>,<code>nums1</code>&nbsp;相对于 <code>nums2</code> 的<em>优势</em>可以用满足&nbsp;<code>nums1[i] &gt; nums2[i]</code>&nbsp;的索引 <code>i</code>&nbsp;的数目来描述。</p>
9+
<p>给定两个长度相等的数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>,<code>nums1</code>&nbsp;相对于 <code>nums2</code> 的<em>优势</em>可以用满足&nbsp;<code>nums1[i] &gt; nums2[i]</code>&nbsp;的索引 <code>i</code>&nbsp;的数目来描述。</p>
1010

1111
<p>返回 <font color="#c7254e" face="Menlo, Monaco, Consolas, Courier New, monospace" size="1"><span style="background-color: rgb(249, 242, 244);">nums1</span></font>&nbsp;的<strong>任意</strong>排列,使其相对于 <code>nums2</code>&nbsp;的优势最大化。</p>
1212

solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md

+3-16
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,32 @@
99
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>
1010

1111
<p>&nbsp;</p>
12-
1312
<p><strong class="example">Example 1:</strong></p>
1413

1514
<pre>
16-
1715
<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2
18-
1916
<strong>Output:</strong> 4
20-
2117
<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:
22-
2318
[<u><strong>1,0,1</strong></u>,0,1]
24-
2519
[<u><strong>1,0,1,0</strong></u>,1]
26-
2720
[1,<u><strong>0,1,0,1</strong></u>]
28-
2921
[1,0,<u><strong>1,0,1</strong></u>]
30-
3122
</pre>
3223

3324
<p><strong class="example">Example 2:</strong></p>
3425

3526
<pre>
36-
3727
<strong>Input:</strong> nums = [0,0,0,0,0], goal = 0
38-
3928
<strong>Output:</strong> 15
40-
4129
</pre>
4230

4331
<p>&nbsp;</p>
44-
4532
<p><strong>Constraints:</strong></p>
4633

4734
<ul>
48-
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
49-
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
50-
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
35+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
36+
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
37+
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
5138
</ul>
5239

5340
## Solutions

solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定一棵二叉树的根 <code>root</code>,请你考虑它所有&nbsp;<strong>从根到叶的路径</strong>:从根到任何叶的路径。(所谓一个叶子节点,就是一个没有子节点的节点)</p>
9+
<p>给你二叉树的根节点 <code>root</code> 和一个整数 <code>limit</code> ,请你同时删除树中所有 <strong>不足节点 </strong>,并返回最终二叉树的根节点。</p>
1010

11-
<p>假如通过节点 <code>node</code> 的每种可能的 &ldquo;根-叶&rdquo; 路径上值的总和全都小于给定的 <code>limit</code>,则该节点被称之为不足节点,需要被删除。</p>
11+
<p>假如通过节点 <code>node</code> 的每种可能的 根-叶 路径上值的总和全都小于给定的 <code>limit</code>,则该节点被称之为<strong> 不足节点 </strong>,需要被删除。</p>
1212

13-
<p>请你删除所有不足节点,并返回生成的二叉树的根。</p>
13+
<p><strong>叶子节点</strong>,就是没有子节点的节点。</p>
1414

1515
<p>&nbsp;</p>
1616

17-
<p><strong>示例 1:</strong></p>
18-
19-
<pre><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-1.png" style="height: 200px; width: 482px;">
20-
输入:</strong>root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1
21-
<strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-2.png" style="height: 200px; width: 258px;">
22-
输出:</strong>[1,2,3,4,null,null,7,8,9,null,14]
17+
<p><strong class="example">示例 1:</strong></p>
18+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-11.png" style="width: 500px; height: 207px;" />
19+
<pre>
20+
<strong>输入:</strong>root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1
21+
<strong>输出:</strong>[1,2,3,4,null,null,7,8,9,null,14]
2322
</pre>
2423

25-
<p><strong>示例 2:</strong></p>
26-
27-
<pre><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-3.png" style="height: 200px; width: 292px;">
28-
输入:</strong>root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22
29-
<strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-4.png" style="height: 200px; width: 264px;">
30-
输出:</strong>[5,4,8,11,null,17,4,7,null,null,null,5]</pre>
31-
32-
<p><strong>示例 3:</strong></p>
24+
<p><strong class="example">示例 2:</strong></p>
25+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-3.png" style="width: 400px; height: 274px;" />
26+
<pre>
27+
<strong>输入:</strong>root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22
28+
<strong>输出:</strong>[5,4,8,11,null,17,4,7,null,null,null,5]
29+
</pre>
3330

34-
<pre><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-5.png" style="height: 100px; width: 140px;">
35-
输入:</strong>root = [5,-6,-6], limit = 0<strong>
36-
输出:</strong>[]</pre>
31+
<p><strong class="example">示例 3:</strong></p>
32+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/screen-shot-2019-06-11-at-83301-pm.png" style="width: 250px; height: 199px;" />
33+
<pre>
34+
<strong>输入:</strong>root = [1,2,-3,-5,null,4,null], limit = -1
35+
<strong>输出:</strong>[1,null,-3,4]
36+
</pre>
3737

3838
<p>&nbsp;</p>
3939

4040
<p><strong>提示:</strong></p>
4141

42-
<ol>
43-
<li>给定的树有&nbsp;<code>1</code>&nbsp;到&nbsp;<code>5000</code>&nbsp;个节点</li>
44-
<li><code>-10^5&nbsp;&lt;= node.val &lt;= 10^5</code></li>
45-
<li><code>-10^9 &lt;= limit&nbsp;&lt;= 10^9</code></li>
46-
</ol>
42+
<ul>
43+
<li>树中节点数目在范围 <code>[1, 5000]</code></li>
44+
<li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
45+
<li><code>-10<sup>9</sup> &lt;= limit &lt;= 10<sup>9</sup></code></li>
46+
</ul>
4747

4848
<p>&nbsp;</p>
4949

0 commit comments

Comments
 (0)