Skip to content

Commit 2d7c1e4

Browse files
authored
feat: update lc problems (#3381)
1 parent 20e15cd commit 2d7c1e4

File tree

37 files changed

+283
-162
lines changed

37 files changed

+283
-162
lines changed

solution/0000-0099/0010.Regular Expression Matching/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tags:
2525
<li><code>'*'</code> 匹配零个或多个前面的那一个元素</li>
2626
</ul>
2727

28-
<p>所谓匹配,是要涵盖&nbsp;<strong>整个&nbsp;</strong>字符串&nbsp;<code>s</code>的,而不是部分字符串。</p>
28+
<p>所谓匹配,是要涵盖&nbsp;<strong>整个&nbsp;</strong>字符串&nbsp;<code>s</code> 的,而不是部分字符串。</p>
2929
&nbsp;
3030

3131
<p><strong>示例 1:</strong></p>

solution/0000-0099/0075.Sort Colors/README.md

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

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

21-
<p>给定一个包含红色、白色和蓝色、共&nbsp;<code>n</code><em> </em>个元素的数组<meta charset="UTF-8" />&nbsp;<code>nums</code>&nbsp;,<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>
21+
<p>给定一个包含红色、白色和蓝色、共&nbsp;<code>n</code><em> </em>个元素的数组<meta charset="UTF-8" />&nbsp;<code>nums</code>&nbsp;,<strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地</a>&nbsp;</strong>对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。</p>
2222

2323
<p>我们使用整数 <code>0</code>、&nbsp;<code>1</code> 和 <code>2</code> 分别表示红色、白色和蓝色。</p>
2424

solution/0000-0099/0085.Maximal Rectangle/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tags:
2525
<p>&nbsp;</p>
2626

2727
<p><strong>示例 1:</strong></p>
28-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0085.Maximal%20Rectangle/images/maximal.jpg" style="width: 402px; height: 322px;" />
28+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0085.Maximal%20Rectangle/images/1722912576-boIxpm-image.png" style="width: 402px; height: 322px;" />
2929
<pre>
3030
<strong>输入:</strong>matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
3131
<strong>输出:</strong>6
Loading

solution/0200-0299/0277.Find the Celebrity/README.md

+25-31
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,56 @@ tags:
1818

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

21-
<p>假设你是一个专业的狗仔,参加了一个 <code>n</code> 人派对,其中每个人被从 <code>0</code> 到 <code>n - 1</code> 标号。在这个派对人群当中可能存在一位 “名人”。所谓 “名人” 的定义是:其他所有 <code>n - 1</code> 个人都认识他/她,而他/她并不认识其他任何人。</p>
21+
<p>假设你是一个专业的狗仔,参加了一个&nbsp;<code>n</code>&nbsp;人派对,其中每个人被从&nbsp;<code>0</code>&nbsp;&nbsp;<code>n - 1</code>&nbsp;标号。在这个派对人群当中可能存在一位&nbsp;“名人”。所谓 “名人” 的定义是:其他所有&nbsp;<code>n - 1</code>&nbsp;个人都认识他/她,而他/她并不认识其他任何人。</p>
2222

23-
<p>现在你想要确认这个 “名人” 是谁,或者确定这里没有 “名人”。而你唯一能做的就是问诸如 “A 你好呀,请问你认不认识 B呀?” 的问题,以确定 A 是否认识 B。你需要在(渐近意义上)尽可能少的问题内来确定这位 “名人” 是谁(或者确定这里没有 “名人”)。</p>
23+
<p>现在你想要确认这个 “名人” 是谁,或者确定这里没有&nbsp;“名人”。而你唯一能做的就是问诸如 “A&nbsp;你好呀,请问你认不认识&nbsp;B呀?”&nbsp;的问题,以确定 A 是否认识 B。你需要在(渐近意义上)尽可能少的问题内来确定这位 “名人” 是谁(或者确定这里没有 “名人”)。</p>
2424

25-
<p>在本题中,你可以使用辅助函数 <code>bool knows(a, b)</code> 获取到 A 是否认识 B。请你来实现一个函数 <code>int findCelebrity(n)</code>。</p>
25+
<p>在本题中,你可以使用辅助函数&nbsp;<code>bool knows(a, b)</code>&nbsp;获取到 A&nbsp;是否认识 B。请你来实现一个函数&nbsp;<code>int findCelebrity(n)</code>。</p>
2626

27-
<p>派对最多只会有一个 “名人” 参加。若 “名人” 存在,请返回他/她的编号;若 “名人” 不存在,请返回 <code>-1</code>。</p>
27+
<p>派对最多只会有一个 “名人” 参加。若&nbsp;“名人” 存在,请返回他/她的编号;若&nbsp;“名人”&nbsp;不存在,请返回&nbsp;<code>-1</code>。</p>
2828

29-
<p> </p>
30-
31-
<p><strong>示例 1:</strong></p>
32-
33-
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0277.Find%20the%20Celebrity/images/277_example_1_bold.png" style="height: 181px; width: 186px;" /></p>
29+
<p>&nbsp;</p>
3430

31+
<p><strong class="example">示例 1:</strong></p>
32+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0277.Find%20the%20Celebrity/images/g1.jpg" style="width: 224px; height: 145px;" />
3533
<pre>
36-
<strong>输入: </strong>graph = [
37-
  [1,1,0],
38-
  [0,1,0],
39-
  [1,1,1]
40-
]
34+
<strong>输入: </strong>graph = [[1,1,0],[0,1,0],[1,1,1]]
4135
<strong>输出: </strong>1
4236
<strong>解释: </strong>有编号分别为 0、1 和 2 的三个人。graph[i][j] = 1 代表编号为 i 的人认识编号为 j 的人,而 graph[i][j] = 0 则代表编号为 i 的人不认识编号为 j 的人。“名人” 是编号 1 的人,因为 0 和 2 均认识他/她,但 1 不认识任何人。
4337
</pre>
38+
<strong> </strong>
4439

45-
<p><strong>示例 2:</strong></p>
46-
47-
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0277.Find%20the%20Celebrity/images/277_example_2.png" style="height: 192px; width: 193px;" /></p>
48-
40+
<p><strong><strong class="example">示例&nbsp;2:</strong></strong></p>
41+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0277.Find%20the%20Celebrity/images/g2.jpg" style="width: 224px; height: 145px;" />
4942
<pre>
50-
<strong>输入: </strong>graph = [
51-
  [1,0,1],
52-
  [1,1,0],
53-
  [0,1,1]
54-
]
43+
<strong>输入: </strong>graph = [[1,0,1],[1,1,0],[0,1,1]]
5544
<strong>输出: </strong>-1
5645
<strong>解释: </strong>没有 “名人”
5746
</pre>
5847

59-
<p> </p>
48+
<p><strong>&nbsp;</strong></p>
49+
<strong> </strong>
6050

61-
<p><strong>提示:</strong></p>
51+
<p><strong><strong>提示:</strong></strong></p>
52+
<strong> </strong>
6253

6354
<ul>
64-
<li><code>n == graph.length</code></li>
65-
<li><code>n == graph[i].length</code></li>
66-
<li><code>2 <= n <= 100</code></li>
67-
<li><code>graph[i][j]</code> 是 <code>0</code> 或 <code>1</code>.</li>
55+
<li><code>n == graph.length == graph[i].length</code></li>
56+
<li><code>2 &lt;= n &lt;= 100</code></li>
57+
<li><code>graph[i][j]</code> 是 <code>0</code> 或 <code>1</code></li>
6858
<li><code>graph[i][i] == 1</code></li>
6959
</ul>
60+
<strong> </strong>
7061

71-
<p> </p>
62+
<p><strong>&nbsp;</strong></p>
63+
<strong> </strong>
7264

73-
<p><strong>进阶:</strong>如果允许调用 API <code>knows</code> 的最大次数为 <code>3 * n</code> ,你可以设计一个不超过最大调用次数的解决方案吗?</p>
65+
<p><strong><strong>进阶:</strong></strong>如果允许调用 API <code>knows</code> 的最大次数为 <code>3 * n</code> ,你可以设计一个不超过最大调用次数的解决方案吗?</p>
66+
<strong> </strong>
7467

7568
<ol>
7669
</ol>
70+
<strong> </strong>
7771

7872
<!-- description:end -->
7973

Binary file not shown.
Binary file not shown.

solution/0500-0599/0588.Design In-Memory File System/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tags:
77
- 字典树
88
- 哈希表
99
- 字符串
10+
- 排序
1011
---
1112

1213
<!-- problem:start -->

solution/0500-0599/0588.Design In-Memory File System/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tags:
77
- Trie
88
- Hash Table
99
- String
10+
- Sorting
1011
---
1112

1213
<!-- problem:start -->

solution/0600-0699/0642.Design Search Autocomplete System/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/0600-0699/0642.Design%20Search%20Autocomplete%20System/README.md
55
tags:
6+
- 深度优先搜索
67
- 设计
78
- 字典树
89
- 字符串

solution/0600-0699/0642.Design Search Autocomplete System/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ comments: true
33
difficulty: Hard
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README_EN.md
55
tags:
6+
- Depth-First Search
67
- Design
78
- Trie
89
- String

solution/0700-0799/0713.Subarray Product Less Than K/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tags:
2626
<pre>
2727
<strong>输入:</strong>nums = [10,5,2,6], k = 100
2828
<strong>输出:</strong>8
29-
<strong>解释:</strong>8 个乘积小于 100 的子数组分别为:[10]、[5]、[2],、[6]、[10,5]、[5,2]、[2,6]、[5,2,6]。
29+
<strong>解释:</strong>8 个乘积小于 100 的子数组分别为:[10]、[5]、[2]、[6]、[10,5]、[5,2]、[2,6]、[5,2,6]。
3030
需要注意的是 [10,5,2] 并不是乘积小于 100 的子数组。
3131
</pre>
3232

solution/0800-0899/0840.Magic Squares In Grid/README.md

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

2424
<p>给定一个由整数组成的<code>row x col</code>&nbsp;的 <code>grid</code>,其中有多少个&nbsp;<code>3 × 3</code> 的 “幻方” 子矩阵?(每个子矩阵都是连续的)。</p>
2525

26+
<p>注意:虽然幻方只能包含 1 到 9 的数字,但&nbsp;<code>grid</code> 可以包含最多15的数字。</p>
27+
2628
<p>&nbsp;</p>
2729

2830
<p><strong>示例 1:</strong></p>

solution/0800-0899/0840.Magic Squares In Grid/README_EN.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ tags:
1919

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

22-
<p>A <code>3 x 3</code> magic square is a <code>3 x 3</code> grid filled with distinct numbers <strong>from </strong><code>1</code><strong> to </strong><code>9</code> such that each row, column, and both diagonals all have the same sum.</p>
22+
<p>A <code>3 x 3</code> <strong>magic square</strong> is a <code>3 x 3</code> grid filled with distinct numbers <strong>from </strong>1<strong> to </strong>9 such that each row, column, and both diagonals all have the same sum.</p>
2323

24-
<p>Given a <code>row x col</code>&nbsp;<code>grid</code>&nbsp;of integers, how many <code>3 x 3</code> &quot;magic square&quot; subgrids are there?&nbsp; (Each subgrid is contiguous).</p>
24+
<p>Given a <code>row x col</code> <code>grid</code> of integers, how many <code>3 x 3</code> contiguous magic square subgrids are there?</p>
25+
26+
<p>Note: while a magic square can only contain numbers from 1 to 9, <code>grid</code> may contain numbers up to 15.</p>
2527

2628
<p>&nbsp;</p>
2729
<p><strong class="example">Example 1:</strong></p>

solution/0800-0899/0898.Bitwise ORs of Subarrays/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ tags:
1818

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

21-
<p>我们有一个非负整数数组<meta charset="UTF-8" />&nbsp;<code>arr</code>&nbsp;。</p>
21+
<p>给定一个整数数组<meta charset="UTF-8" />&nbsp;<code>arr</code>,返回所有&nbsp;<code>arr</code>&nbsp;的非空子数组的不同按位或的数量。</p>
2222

23-
<p>对于每个(连续的)子数组<meta charset="UTF-8" />&nbsp;<code>sub = [arr[i], arr[i + 1], ..., arr[j]]</code>&nbsp;&nbsp;<code>i &lt;= j</code>),我们对<meta charset="UTF-8" />&nbsp;<code>sub</code>&nbsp;中的每个元素进行按位或操作,获得结果<meta charset="UTF-8" />&nbsp;<code>arr[i] | arr[i + 1] | ... | arr[j]</code>&nbsp;。</p>
23+
<p>子数组的按位或是子数组中每个整数的按位或。含有一个整数的子数组的按位或就是该整数。</p>
2424

25-
<p>返回可能结果的数量。 多次出现的结果在最终答案中仅计算一次。</p>
25+
<p><strong>子数组</strong> 是数组内连续的非空元素序列。</p>
2626

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

@@ -61,7 +61,7 @@ tags:
6161

6262
<ul>
6363
<li><code>1 &lt;= nums.length &lt;= 5 * 10<sup>4</sup></code></li>
64-
<li><code>0 &lt;= nums[i]&nbsp;&lt;= 10<sup>9</sup></code>​​​​​​​</li>
64+
<li><code>0 &lt;= nums[i]&nbsp;&lt;= 10<sup>9</sup></code></li>
6565
</ul>
6666

6767
<!-- description:end -->

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

+3-20
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,32 @@ tags:
2424
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>
2525

2626
<p>&nbsp;</p>
27-
2827
<p><strong class="example">Example 1:</strong></p>
2928

3029
<pre>
31-
3230
<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2
33-
3431
<strong>Output:</strong> 4
35-
3632
<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:
37-
3833
[<u><strong>1,0,1</strong></u>,0,1]
39-
4034
[<u><strong>1,0,1,0</strong></u>,1]
41-
4235
[1,<u><strong>0,1,0,1</strong></u>]
43-
4436
[1,0,<u><strong>1,0,1</strong></u>]
45-
4637
</pre>
4738

4839
<p><strong class="example">Example 2:</strong></p>
4940

5041
<pre>
51-
5242
<strong>Input:</strong> nums = [0,0,0,0,0], goal = 0
53-
5443
<strong>Output:</strong> 15
55-
5644
</pre>
5745

5846
<p>&nbsp;</p>
59-
6047
<p><strong>Constraints:</strong></p>
6148

6249
<ul>
63-
64-
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
65-
66-
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
67-
68-
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
69-
50+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
51+
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
52+
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
7053
</ul>
7154

7255
<!-- description:end -->

solution/1000-1099/1002.Find Common Characters/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tags:
2020

2121
<!-- description:start -->
2222

23-
给你一个字符串数组 <code>words</code> ,请你找出所有在 <code>words</code> 的每个字符串中都出现的共用字符( <strong>包括重复字符</strong>),并以数组形式返回。你可以按 <strong>任意顺序</strong> 返回答案。
23+
给你一个字符串数组 <code>words</code> ,请你找出所有在 <code>words</code> 的每个字符串中都出现的共用字符(<strong>包括重复字符</strong>),并以数组形式返回。你可以按 <strong>任意顺序</strong> 返回答案。
2424

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

solution/1300-1399/1395.Count Number of Teams/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rating: 1343
66
source: 第 182 场周赛 Q2
77
tags:
88
- 树状数组
9+
- 线段树
910
- 数组
1011
- 动态规划
1112
---

solution/1300-1399/1395.Count Number of Teams/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rating: 1343
66
source: Weekly Contest 182 Q2
77
tags:
88
- Binary Indexed Tree
9+
- Segment Tree
910
- Array
1011
- Dynamic Programming
1112
---

solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ tags:
7373
我们可以使用二维前缀和来快速计算出每个子矩形中苹果的数量,定义 $s[i][j]$ 表示矩形前 $i$ 行,前 $j$ 列的子矩形中苹果的数量,那么 $s[i][j]$ 可以由 $s[i-1][j]$, $s[i][j-1]$, $s[i-1][j-1]$ 三个子矩形的苹果数量求得,具体的计算方法如下:
7474

7575
$$
76-
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + (pizza[i-1][j-1] == 'A')
76+
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + \textit{int}(pizza[i-1][j-1] == 'A')
7777
$$
7878

7979
其中 $pizza[i-1][j-1]$ 表示矩形中第 $i$ 行,第 $j$ 列的字符,如果是苹果,则为 $1$,否则为 $0$。

solution/1400-1499/1444.Number of Ways of Cutting a Pizza/README_EN.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,30 @@ tags:
6969

7070
<!-- solution:start -->
7171

72-
### Solution 1
72+
### Solution 1: 2D Prefix Sum + Memoized Search
73+
74+
We can use a 2D prefix sum to quickly calculate the number of apples in each sub-rectangle. Define $s[i][j]$ to represent the number of apples in the sub-rectangle that includes the first $i$ rows and the first $j$ columns. Then $s[i][j]$ can be derived from the number of apples in the three sub-rectangles $s[i-1][j]$, $s[i][j-1]$, and $s[i-1][j-1]$. The specific calculation method is as follows:
75+
76+
$$
77+
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + (pizza[i-1][j-1] == 'A')
78+
$$
79+
80+
Here, $pizza[i-1][j-1]$ represents the character at the $i$-th row and $j$-th column in the rectangle. If it is an apple, it is $1$; otherwise, it is $0$.
81+
82+
Next, we design a function $dfs(i, j, k)$, which represents the number of ways to cut the rectangle $(i, j, m-1, n-1)$ with $k$ cuts to get $k+1$ pieces of pizza. Here, $(i, j)$ and $(m-1, n-1)$ are the coordinates of the top-left and bottom-right corners of the rectangle, respectively. The calculation method of the function $dfs(i, j, k)$ is as follows:
83+
84+
- If $k = 0$, it means no more cuts can be made. We need to check if there are any apples in the rectangle. If there are apples, return $1$; otherwise, return $0$.
85+
- If $k \gt 0$, we need to enumerate the position of the last cut. If the last cut is horizontal, we need to enumerate the cutting position $x$, where $i \lt x \lt m$. If $s[x][n] - s[i][n] - s[x][j] + s[i][j] \gt 0$, it means there are apples in the upper piece of pizza, and we add the value of $dfs(x, j, k-1)$ to the answer. If the last cut is vertical, we need to enumerate the cutting position $y$, where $j \lt y \lt n$. If $s[m][y] - s[i][y] - s[m][j] + s[i][j] \gt 0$, it means there are apples in the left piece of pizza, and we add the value of $dfs(i, y, k-1)$ to the answer.
86+
87+
The final answer is the value of $dfs(0, 0, k-1)$.
88+
89+
To avoid repeated calculations, we can use memoized search. We use a 3D array $f$ to record the value of $dfs(i, j, k)$. When we need to calculate the value of $dfs(i, j, k)$, if $f[i][j][k]$ is not $-1$, it means we have already calculated it before, and we can directly return $f[i][j][k]$. Otherwise, we calculate the value of $dfs(i, j, k)$ according to the above method and save the result in $f[i][j][k]$.
90+
91+
The time complexity is $O(m \times n \times k \times (m + n))$, and the space complexity is $O(m \times n \times k)$. Here, $m$ and $n$ are the number of rows and columns of the rectangle, respectively.
92+
93+
Similar problems:
94+
95+
- [2312. Selling Pieces of Wood](https://github.com/doocs/leetcode/blob/main/solution/2300-2399/2312.Selling%20Pieces%20of%20Wood/README_EN.md)
7396

7497
<!-- tabs:start -->
7598

solution/1400-1499/1446.Consecutive Characters/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ tags:
5757

5858
### 方法一:遍历计数
5959

60-
我们定义一个变量 $t$,表示当前连续字符的长度,初始时 $t=1$。
60+
我们定义一个变量 $\textit{t}$,表示当前连续字符的长度,初始时 $\textit{t}=1$。
6161

62-
接下来,我们从字符串 $s$ 的第二个字符开始遍历,如果当前字符与上一个字符相同,那么 $t = t + 1$,然后更新答案 $ans = \max(ans, t)$;否则,$t = 1$。
62+
接下来,我们从字符串 $s$ 的第二个字符开始遍历,如果当前字符与上一个字符相同,那么 $\textit{t} = \textit{t} + 1$,然后更新答案 $\textit{ans} = \max(\textit{ans}, \textit{t})$;否则 $\textit{t} = 1$。
6363

64-
最后返回答案 $ans$ 即可。
64+
最后返回答案 $\textit{ans}$ 即可。
6565

6666
时间复杂度 $O(n)$,其中 $n$ 是字符串 $s$ 的长度。空间复杂度 $O(1)$。
6767

solution/1400-1499/1446.Consecutive Characters/README_EN.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ tags:
5353

5454
<!-- solution:start -->
5555

56-
### Solution 1
56+
### Solution 1: Traversal and Counting
57+
58+
We define a variable $\textit{t}$ to represent the length of the current consecutive characters, initially $\textit{t}=1$.
59+
60+
Next, we traverse the string $s$ starting from the second character. If the current character is the same as the previous character, then $\textit{t} = \textit{t} + 1$, and update the answer $\textit{ans} = \max(\textit{ans}, \textit{t})$; otherwise, set $\textit{t} = 1$.
61+
62+
Finally, return the answer $\textit{ans}$.
63+
64+
The time complexity is $O(n)$, where $n$ is the length of the string $s$. The space complexity is $O(1)$.
5765

5866
<!-- tabs:start -->
5967

solution/1800-1899/1820.Maximum Number of Accepted Invitations/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/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README.md
55
tags:
6+
-
67
- 数组
78
- 回溯
89
- 矩阵

solution/1800-1899/1820.Maximum Number of Accepted Invitations/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/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README_EN.md
55
tags:
6+
- Graph
67
- Array
78
- Backtracking
89
- Matrix

0 commit comments

Comments
 (0)