Skip to content

Commit d7ce7a4

Browse files
authored
feat: update lc problems (doocs#3125)
1 parent b0821cc commit d7ce7a4

File tree

43 files changed

+310
-85
lines changed

Some content is hidden

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

43 files changed

+310
-85
lines changed

solution/0100-0199/0130.Surrounded Regions/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ tags:
2828
<li><strong>围绕:</strong>如果您可以用&nbsp;<code>'X'</code>&nbsp;单元格 <strong>连接这个区域</strong>,并且区域中没有任何单元格位于&nbsp;<code>board</code> 边缘,则该区域被 <code>'X'</code>&nbsp;单元格围绕。</li>
2929
</ul>
3030

31+
<p>通过将输入矩阵&nbsp;<code>board</code> 中的所有 <code>'O'</code>&nbsp;替换为 <code>'X'</code> 来 <strong>捕获被围绕的区域</strong>。</p>
32+
3133
<div class="original__bRMd">
3234
<div>
3335
<p>&nbsp;</p>

solution/0400-0499/0431.Encode N-ary Tree to Binary Tree/README.md

+34-3
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,47 @@ tags:
2626

2727
<p>&nbsp;</p>
2828

29-
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/images/narytreebinarytreeexample.png" style="width: 500px;"></p>
29+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/images/narytreebinarytreeexample.png" style="width: 500px;" /></p>
3030

3131
<p>&nbsp;</p>
3232

33+
<pre>
34+
<strong>输入:</strong>root = [1,null,3,2,4,null,5,6]
35+
</pre>
36+
3337
<p>注意,上面的方法仅仅是一个例子,可能可行也可能不可行。你没有必要遵循这种形式转化,你可以自己创造和实现不同的方法。</p>
3438

35-
<p><strong>注意:</strong></p>
39+
<p>&nbsp;</p>
40+
41+
<p><strong class="example">示例 1:</strong></p>
42+
43+
<pre>
44+
<strong>输入:</strong>root = [1,null,3,2,4,null,5,6]
45+
<strong>输出:</strong>[1,null,3,2,4,null,5,6]
46+
</pre>
47+
48+
<p><strong class="example">示例 2:</strong></p>
49+
50+
<pre>
51+
<strong>输入:</strong>root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
52+
<strong>输出:</strong>[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
53+
</pre>
54+
55+
<p><strong class="example">示例 3:</strong></p>
56+
57+
<pre>
58+
<strong>输入:</strong>root = []
59+
<strong>输出:</strong>[]
60+
</pre>
61+
62+
<p>&nbsp;</p>
63+
64+
<p><strong>提示:</strong></p>
3665

3766
<ol>
38-
<li><code>N</code>&nbsp;的范围在 <code>[1, 1000]</code></li>
67+
<li><code>N</code>&nbsp;的范围在 <code>[1, 10<sup>4</sup>]</code></li>
68+
<li><code>0 &lt;= Node.val &lt;= 10<sup>4</sup></code></li>
69+
<li>N 叉树的高度小于等于&nbsp;<code>1000</code>。</li>
3970
<li>不要使用类成员 / 全局变量 / 静态变量来存储状态。你的编码和解码算法应是无状态的。</li>
4071
</ol>
4172

solution/0400-0499/0469.Convex Polygon/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ difficulty: 中等
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0400-0499/0469.Convex%20Polygon/README.md
55
tags:
66
- 几何
7+
- 数组
78
- 数学
89
---
910

solution/0400-0499/0469.Convex Polygon/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ difficulty: Medium
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0400-0499/0469.Convex%20Polygon/README_EN.md
55
tags:
66
- Geometry
7+
- Array
78
- Math
89
---
910

solution/0500-0599/0536.Construct Binary Tree from String/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ comments: true
33
difficulty: 中等
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README.md
55
tags:
6+
-
67
-
78
- 深度优先搜索
89
- 字符串

solution/0500-0599/0536.Construct Binary Tree from String/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ comments: true
33
difficulty: Medium
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README_EN.md
55
tags:
6+
- Stack
67
- Tree
78
- Depth-First Search
89
- String

solution/0500-0599/0558.Logical OR of Two Binary Grids Represented as Quad-Trees/README.md

+9-33
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ tags:
3535
<pre>
3636
class Node {
3737
public boolean val;
38-
    public boolean isLeaf;
39-
    public Node topLeft;
40-
    public Node topRight;
41-
    public Node bottomLeft;
42-
    public Node bottomRight;
38+
&nbsp; &nbsp; public boolean isLeaf;
39+
&nbsp; &nbsp; public Node topLeft;
40+
&nbsp; &nbsp; public Node topRight;
41+
&nbsp; &nbsp; public Node bottomLeft;
42+
&nbsp; &nbsp; public Node bottomRight;
4343
}</pre>
4444

4545
<p>我们可以按以下步骤为二维区域构建四叉树:</p>
@@ -60,9 +60,9 @@ class Node {
6060

6161
<p>它与二叉树的序列化非常相似。唯一的区别是节点以列表形式表示 <code>[isLeaf, val]</code> 。</p>
6262

63-
<p>如果 <code>isLeaf</code> 或者 <code>val</code> 的值为 True ,则表示它在列表 <code>[isLeaf, val]</code> 中的值为 <strong>1</strong> ;如果 <code>isLeaf</code> 或者 <code>val</code> 的值为 False ,则表示值为 <strong>0 </strong>。</p>
63+
<p>如果 <code>isLeaf</code> 或者 <code>val</code> 的值为 True ,则表示它在列表&nbsp;<code>[isLeaf, val]</code> 中的值为 <strong>1</strong> ;如果 <code>isLeaf</code> 或者 <code>val</code> 的值为 False ,则表示值为 <strong>0 </strong>。</p>
6464

65-
<p> </p>
65+
<p>&nbsp;</p>
6666

6767
<p><strong>示例 1:</strong></p>
6868

@@ -88,37 +88,13 @@ class Node {
8888
结果矩阵大小为 1*1,值全为 0 。
8989
</pre>
9090

91-
<p><strong>示例 3:</strong></p>
92-
93-
<pre>
94-
<strong>输入:</strong>quadTree1 = [[0,0],[1,0],[1,0],[1,1],[1,1]]
95-
, quadTree2 = [[0,0],[1,1],[1,1],[1,0],[1,1]]
96-
<strong>输出:</strong>[[1,1]]
97-
</pre>
98-
99-
<p><strong>示例 4:</strong></p>
100-
101-
<pre>
102-
<strong>输入:</strong>quadTree1 = [[0,0],[1,1],[1,0],[1,1],[1,1]]
103-
, quadTree2 = [[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]
104-
<strong>输出:</strong>[[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]
105-
</pre>
106-
107-
<p><strong>示例 5:</strong></p>
108-
109-
<pre>
110-
<strong>输入:</strong>quadTree1 = [[0,1],[1,0],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]
111-
, quadTree2 = [[0,1],[0,1],[1,0],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1]]
112-
<strong>输出:</strong>[[0,0],[0,1],[0,1],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1],[1,0],[1,0],[1,1],[1,1]]
113-
</pre>
114-
115-
<p> </p>
91+
<p>&nbsp;</p>
11692

11793
<p><strong>提示:</strong></p>
11894

11995
<ul>
12096
<li><code>quadTree1</code> 和 <code>quadTree2</code> 都是符合题目要求的四叉树,每个都代表一个 <code>n * n</code> 的矩阵。</li>
121-
<li><code>n == 2^x</code> ,其中 <code>0 <= x <= 9</code>.</li>
97+
<li><code>n == 2<sup>x</sup></code>&nbsp;,其中 <code>0 &lt;= x &lt;= 9</code>.</li>
12298
</ul>
12399

124100
<!-- description:end -->

solution/1400-1499/1490.Clone N-ary Tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Node {
5858

5959
<ul>
6060
<li>给定的 N 叉树的深度小于或等于&nbsp;<code>1000</code>。</li>
61-
<li>节点的总个数在&nbsp;<code>[0,&nbsp;10^4]</code>&nbsp;之间</li>
61+
<li>节点的总个数在&nbsp;<code>[0,&nbsp;10<sup>4</sup>]</code>&nbsp;之间</li>
6262
</ul>
6363

6464
<p>&nbsp;</p>

solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1600-1699/1612.Ch
55
tags:
66
-
77
- 深度优先搜索
8+
- 哈希表
89
- 二叉树
10+
- 计数
911
---
1012

1113
<!-- problem:start -->

solution/1600-1699/1612.Check If Two Expression Trees are Equivalent/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1600-1699/1612.Ch
55
tags:
66
- Tree
77
- Depth-First Search
8+
- Hash Table
89
- Binary Tree
10+
- Counting
911
---
1012

1113
<!-- problem:start -->

solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1600-1699/1625.Le
55
rating: 1992
66
source: 第 211 场周赛 Q2
77
tags:
8+
- 深度优先搜索
89
- 广度优先搜索
910
- 字符串
11+
- 枚举
1012
---
1113

1214
<!-- problem:start -->

solution/1600-1699/1625.Lexicographically Smallest String After Applying Operations/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1600-1699/1625.Le
55
rating: 1992
66
source: Weekly Contest 211 Q2
77
tags:
8+
- Depth-First Search
89
- Breadth-First Search
910
- String
11+
- Enumeration
1012
---
1113

1214
<!-- problem:start -->

solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tags:
66
-
77
-
88
- 设计
9+
- 数组
910
- 数学
1011
- 二叉树
1112
---

solution/1600-1699/1628.Design an Expression Tree With Evaluate Function/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tags:
66
- Stack
77
- Tree
88
- Design
9+
- Array
910
- Math
1011
- Binary Tree
1112
---

solution/1600-1699/1638.Count Substrings That Differ by One Character/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tags:
88
- 哈希表
99
- 字符串
1010
- 动态规划
11+
- 枚举
1112
---
1213

1314
<!-- problem:start -->

solution/1600-1699/1638.Count Substrings That Differ by One Character/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tags:
88
- Hash Table
99
- String
1010
- Dynamic Programming
11+
- Enumeration
1112
---
1213

1314
<!-- problem:start -->

solution/2600-2699/2644.Find the Maximum Divisibility Score/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ tags:
3737

3838
<p><code>divisors[0]</code>&nbsp;的可整除性分数为 2 因为&nbsp;<code>nums[2]</code> 和&nbsp;<code>nums[3]</code>&nbsp;能被 5 整除。</p>
3939

40-
<p><code>divisors[1]</code> 的可整除性分数为 1 因为只有 <code>nums[1]</code>&nbsp;能被 3 整除。</p>
40+
<p><code>divisors[1]</code> 的可整除性分数为 2 因为&nbsp;<code>nums[1]</code>&nbsp;&nbsp;<code>nums[2]</code>&nbsp;能被 3 整除。</p>
4141

4242
<p><code>divisors[2]</code> 的可整除性分数为 0 因为&nbsp;<code>nums</code>&nbsp;中没有数字能被 7 整除。</p>
4343

4444
<p><code>divisors[3]</code> 的可整除性分数为 2 因为 <code>nums[0]</code> 和&nbsp;<code>nums[3]</code>&nbsp;能够被 2 整除。</p>
4545

46-
<p>因为&nbsp;<code>divisors[0]</code> 和&nbsp;<code>divisors[3]</code>&nbsp;有相同的可整除性分数,我们返回更小的那个&nbsp;<code>divisors[3]</code>。</p>
46+
<p>因为&nbsp;<code>divisors[0]</code>&nbsp;、<code>divisor[1]</code>&nbsp;<code>divisors[3]</code>&nbsp;有相同的可整除性分数,我们返回更小的那个&nbsp;<code>divisors[3]</code>。</p>
4747
</div>
4848

4949
<p><strong class="example">示例 2:</strong></p>
@@ -71,13 +71,13 @@ tags:
7171

7272
<p><strong>解释:</strong></p>
7373

74-
<p><code>divisors[0]</code> 的可整除性分数为 0 因为&nbsp;<code>nums</code>&nbsp;中没有数字能被 10 整除。</p>
74+
<p><code>divisors[0]</code> 的可整除性分数为 2 因为&nbsp;<code>nums[0]</code>&nbsp;&nbsp;<code>nums[3]</code> 能被 10 整除。</p>
7575

7676
<p><code>divisors[1]</code> 的可整除性分数为 0 因为&nbsp;<code>nums</code>&nbsp;中没有数字能被 16&nbsp;整除。</p>
7777

78-
<p><code>divisors[2]</code> 的可整除性分数为 0 因为&nbsp;<code>nums</code>&nbsp;中没有数字能被 20&nbsp;整除。</p>
78+
<p><code>divisors[2]</code> 的可整除性分数为 1 因为&nbsp;<code>nums[0]</code>&nbsp;能被 20&nbsp;整除。</p>
7979

80-
<p>因为&nbsp;<code>divisors[0]</code>,<code>divisors[1]</code> 和&nbsp;<code>divisors[2]</code>&nbsp;都有相同的可整除性分数,我们返回最小的那个&nbsp;<code>divisors[0]</code>。</p>
80+
<p>因为&nbsp;<code>divisors[0]</code>&nbsp;的可整除性分数最大,我们返回&nbsp;<code>divisors[0]</code>。</p>
8181
</div>
8282

8383
<p>&nbsp;</p>

solution/2600-2699/2644.Find the Maximum Divisibility Score/README_EN.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ tags:
3636

3737
<p>The divisibility score of <code>divisors[0]</code> is 2 since <code>nums[2]</code> and <code>nums[3]</code> are divisible by 5.</p>
3838

39-
<p>The divisibility score of <code>divisors[1]</code> is 1 since only <code>nums[1]</code> is divisible by 3.</p>
39+
<p>The divisibility score of <code>divisors[1]</code> is 2 since <code>nums[1]</code> and <code>nums[2]</code> are divisible by 3.</p>
4040

4141
<p>The divisibility score of <code>divisors[2]</code> is 0 since none of the numbers in <code>nums</code> is divisible by 7.</p>
4242

4343
<p>The divisibility score of <code>divisors[3]</code> is 2 since <code>nums[0]</code> and <code>nums[3]</code> are divisible by 2.</p>
4444

45-
<p>As <code>divisors[0]</code> and <code>divisors[3]</code> have the same divisibility score, we return the smaller one which is <code>divisors[3]</code>.</p>
45+
<p>As <code>divisors[0]</code>,&nbsp;<code>divisors[1]</code>, and <code>divisors[3]</code> have the same divisibility score, we return the smaller one which is <code>divisors[3]</code>.</p>
4646
</div>
4747

4848
<p><strong class="example">Example 2:</strong></p>
@@ -70,13 +70,11 @@ tags:
7070

7171
<p><strong>Explanation:</strong></p>
7272

73-
<p>The divisibility score of <code>divisors[0]</code> is 0 since none of the numbers in <code>nums</code> is divisible by 10.</p>
73+
<p>The divisibility score of <code>divisors[0]</code> is 2 since <code>nums[0]</code> and <code>nums[3]</code> are divisible by 10.</p>
7474

7575
<p>The divisibility score of <code>divisors[1]</code> is 0 since none of the numbers in <code>nums</code> is divisible by 16.</p>
7676

77-
<p>The divisibility score of <code>divisors[2]</code> is 0 since none of the numbers in <code>nums</code> is divisible by 20.</p>
78-
79-
<p>As <code>divisors[0]</code>, <code>divisors[1]</code> and <code>divisors[2]</code> all have the same divisibility score, we return the smallest one which is <code>divisors[0]</code>.</p>
77+
<p>The divisibility score of <code>divisors[2]</code> is 1 since <code>nums[0]</code> is divisible by 20.</p>
8078
</div>
8179

8280
<p>&nbsp;</p>

solution/2700-2799/2713.Maximum Strictly Increasing Cells in a Matrix/README.md

+56-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,17 @@ tags:
8282

8383
<!-- solution:start -->
8484

85-
### 方法一
85+
### 方法一:排序 + 动态规划
86+
87+
根据题目描述,我们顺序移动的单元格的值必须严格递增,因此,我们不妨用一个哈希表 $g$ 来记录每个值对应的所有单元格的位置,然后按照值的大小从小到大遍历。
88+
89+
在这个过程中,我们可以维护两个数组 `rowMax``colMax`,分别记录每一行和每一列的最大递增长度。初始时,这两个数组的所有元素都为 $0$。
90+
91+
对于每个值对应的所有单元格位置,我们按照位置顺序遍历,对于每个位置 $(i, j)$,我们可以计算出以该位置为终点的最大递增长度为 $1 + \max(\text{rowMax}[i], \text{colMax}[j])$,更新答案,然后更新 `rowMax[i]``colMax[j]`
92+
93+
最后返回答案即可。
94+
95+
时间复杂度 $O(m \times n \times \log(m \times n))$,空间复杂度 $O(m \times n)$。
8696

8797
<!-- tabs:start -->
8898

@@ -212,6 +222,51 @@ func maxIncreasingCells(mat [][]int) (ans int) {
212222
}
213223
```
214224

225+
#### TypeScript
226+
227+
```ts
228+
function maxIncreasingCells(mat: number[][]): number {
229+
const m = mat.length;
230+
const n = mat[0].length;
231+
const g: { [key: number]: [number, number][] } = {};
232+
233+
for (let i = 0; i < m; i++) {
234+
for (let j = 0; j < n; j++) {
235+
if (!g[mat[i][j]]) {
236+
g[mat[i][j]] = [];
237+
}
238+
g[mat[i][j]].push([i, j]);
239+
}
240+
}
241+
242+
const rowMax = Array(m).fill(0);
243+
const colMax = Array(n).fill(0);
244+
let ans = 0;
245+
246+
const sortedKeys = Object.keys(g)
247+
.map(Number)
248+
.sort((a, b) => a - b);
249+
250+
for (const key of sortedKeys) {
251+
const pos = g[key];
252+
const mx: number[] = [];
253+
254+
for (const [i, j] of pos) {
255+
mx.push(1 + Math.max(rowMax[i], colMax[j]));
256+
ans = Math.max(ans, mx[mx.length - 1]);
257+
}
258+
259+
for (let k = 0; k < pos.length; k++) {
260+
const [i, j] = pos[k];
261+
rowMax[i] = Math.max(rowMax[i], mx[k]);
262+
colMax[j] = Math.max(colMax[j], mx[k]);
263+
}
264+
}
265+
266+
return ans;
267+
}
268+
```
269+
215270
<!-- tabs:end -->
216271

217272
<!-- solution:end -->

0 commit comments

Comments
 (0)