Skip to content

Commit d0e8c21

Browse files
committed
feat: add new lc problems
1 parent 3f2f432 commit d0e8c21

File tree

41 files changed

+1466
-321
lines changed

Some content is hidden

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

41 files changed

+1466
-321
lines changed

solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<strong>Output:</strong> 4
2525
<strong>Explanation:</strong> Replace the one &#39;A&#39; in the middle with &#39;B&#39; and form &quot;AABBBBA&quot;.
2626
The substring &quot;BBBB&quot; has the longest repeating letters, which is 4.
27-
</pre>
27+
There may exists other ways to achive this answer too.</pre>
2828

2929
<p>&nbsp;</p>
3030
<p><strong>Constraints:</strong></p>

solution/0400-0499/0436.Find Right Interval/README.md

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

99
<p>给你一个区间数组 <code>intervals</code> ,其中&nbsp;<code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> ,且每个&nbsp;<code>start<sub>i</sub></code> 都 <strong>不同</strong> 。</p>
1010

11-
<p>区间 <code>i</code> 的 <strong>右侧区间</strong> 可以记作区间 <code>j</code> ,并满足 <code>start<sub>j</sub></code><code>&nbsp;&gt;= end<sub>i</sub></code> ,且 <code>start<sub>j</sub></code> <strong>最小化 </strong>。</p>
11+
<p>区间 <code>i</code> 的 <strong>右侧区间</strong> 可以记作区间 <code>j</code> ,并满足 <code>start<sub>j</sub></code><code>&nbsp;&gt;= end<sub>i</sub></code> ,且 <code>start<sub>j</sub></code> <strong>最小化 </strong>。注意 <code>i</code> 可能等于 <code>j</code> 。</p>
1212

1313
<p>返回一个由每个区间 <code>i</code> 的 <strong>右侧区间</strong> 在&nbsp;<code>intervals</code> 中对应下标组成的数组。如果某个区间 <code>i</code> 不存在对应的 <strong>右侧区间</strong> ,则下标 <code>i</code> 处的值设为 <code>-1</code> 。</p>
1414
&nbsp;

solution/0800-0899/0852.Peak Index in a Mountain Array/README.md

+11-27
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@
99
符合下列属性的数组 <code>arr</code> 称为 <strong>山脉数组</strong> :
1010

1111
<ul>
12-
<li><code>arr.length >= 3</code></li>
13-
<li>存在 <code>i</code>(<code>0 < i < arr.length - 1</code>)使得:
12+
<li><code>arr.length &gt;= 3</code></li>
13+
<li>存在 <code>i</code>(<code>0 &lt; i&nbsp;&lt; arr.length - 1</code>)使得:
1414
<ul>
15-
<li><code>arr[0] < arr[1] < ... arr[i-1] < arr[i] </code></li>
16-
<li><code>arr[i] > arr[i+1] > ... > arr[arr.length - 1]</code></li>
15+
<li><code>arr[0] &lt; arr[1] &lt; ... arr[i-1] &lt; arr[i] </code></li>
16+
<li><code>arr[i] &gt; arr[i+1] &gt; ... &gt; arr[arr.length - 1]</code></li>
1717
</ul>
1818
</li>
1919
</ul>
2020

21-
<p>给你由整数组成的山脉数组 <code>arr</code> ,返回任何满足 <code>arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1]</code> 的下标 <code>i</code> 。</p>
21+
<p>给你由整数组成的山脉数组 <code>arr</code> ,返回满足 <code>arr[0] &lt; arr[1] &lt; ... arr[i - 1] &lt; arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code> 的下标 <code>i</code> 。</p>
2222

23-
<p> </p>
23+
<p>你必须设计并实现时间复杂度为 <code>O(log(n))</code> 的解决方案。</p>
24+
25+
<p>&nbsp;</p>
2426

2527
<p><strong>示例 1:</strong></p>
2628

@@ -43,34 +45,16 @@
4345
<strong>输出:</strong>1
4446
</pre>
4547

46-
<p><strong>示例 4:</strong></p>
47-
48-
<pre>
49-
<strong>输入:</strong>arr = [3,4,5,1]
50-
<strong>输出:</strong>2
51-
</pre>
52-
53-
<p><strong>示例 5:</strong></p>
54-
55-
<pre>
56-
<strong>输入:</strong>arr = [24,69,100,99,79,78,67,36,26,19]
57-
<strong>输出:</strong>2
58-
</pre>
59-
60-
<p> </p>
48+
<p>&nbsp;</p>
6149

6250
<p><strong>提示:</strong></p>
6351

6452
<ul>
65-
<li><code>3 <= arr.length <= 10<sup>4</sup></code></li>
66-
<li><code>0 <= arr[i] <= 10<sup>6</sup></code></li>
53+
<li><code>3 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
54+
<li><code>0 &lt;= arr[i] &lt;= 10<sup>6</sup></code></li>
6755
<li>题目数据保证 <code>arr</code> 是一个山脉数组</li>
6856
</ul>
6957

70-
<p> </p>
71-
72-
<p><strong>进阶:</strong>很容易想到时间复杂度 <code>O(n)</code> 的解决方案,你可以设计一个 <code>O(log(n))</code> 的解决方案吗?</p>
73-
7458
## 解法
7559

7660
<!-- 这里可写通用的实现逻辑 -->

solution/0800-0899/0877.Stone Game/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Solution:
5757
if i > j:
5858
return 0
5959
return max(piles[i] - dfs(i + 1, j), piles[j] - dfs(i, j - 1))
60-
60+
6161
return dfs(0, len(piles) - 1) > 0
6262
```
6363

solution/1000-1099/1071.Greatest Common Divisor of Strings/README.md

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

99
<p>对于字符串&nbsp;<code>s</code> 和&nbsp;<code>t</code>,只有在&nbsp;<code>s = t + ... + t</code>(<code>t</code> 自身连接 1 次或多次)时,我们才认定&nbsp;“<code>t</code> 能除尽 <code>s</code>”。</p>
1010

11-
<p>给定两个字符串&nbsp;<code>str1</code>&nbsp;&nbsp;<code>str2</code>&nbsp;。返回 <em>最长字符串&nbsp;<code>x</code>,要求满足&nbsp;<code>x</code> 能除尽 <code>str1</code> 且&nbsp;<code>X</code> 能除尽 <code>str2</code></em> 。</p>
11+
<p>给定两个字符串&nbsp;<code>str1</code>&nbsp;&nbsp;<code>str2</code>&nbsp;。返回 <em>最长字符串&nbsp;<code>x</code>,要求满足&nbsp;<code>x</code> 能除尽 <code>str1</code> 且 <code>x</code> 能除尽 <code>str2</code></em> 。</p>
1212

1313
<p>&nbsp;</p>
1414

solution/1300-1399/1339.Maximum Product of Splitted Binary Tree/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public:
160160
}
161161
return t;
162162
};
163-
163+
164164
dfs(root);
165165
return ans % mod;
166166
}

solution/1300-1399/1384.Total Sales Amount by Year/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ product_name 是产品的名称。
3535
product_id 是这张表的主键。
3636
period_start&nbsp;和 period_end&nbsp;是该产品销售期的起始日期和结束日期,且这两个日期包含在销售期内。
3737
average_daily_sales 列存储销售期内该产品的日平均销售额。
38+
销售日期范围为2018年到2020年。
3839
</pre>
3940

4041
<p>&nbsp;</p>
4142

42-
<p>编写一段 SQL 查询每个产品每年的总销售额,并包含 product_id, product_name 以及 report_year 等信息。</p>
43+
<p>编写一段 SQL 查询,查找出每个产品每年的总销售额,并包含 <code>product_id</code> , <code>product_name</code> ,&nbsp;<code>report_year</code> 以及 <code>total_amount</code>&nbsp;。</p>
4344

44-
<p>销售年份的日期介于 2018 年到 2020 年之间。你返回的结果需要按&nbsp;product_id 和 report_year<strong> 排序</strong>。</p>
45+
<p>返回结果并按&nbsp;<code>product_id</code><code>report_year</code><strong> 排序</strong>。</p>
4546

4647
<p>查询结果格式如下例所示。</p>
4748

4849
<p>&nbsp;</p>
4950

50-
<p><strong>示例 1:</strong></p>
51+
<p><strong class="example">示例 1:</strong></p>
5152

5253
<pre>
5354
<code><strong>输入:</strong>

solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The dates of the sales years are between 2018 to 2020.
3838

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

41-
<p>Write an SQL query to report the total sales amount of each item for each year, with corresponding <code>product_name</code>, <code>product_id</code>, <code>product_name</code>, and <code>report_year</code>.</p>
41+
<p>Write an SQL query to report the total sales amount of each item for each year, with corresponding <code>product_name</code>, <code>product_id</code>, <code>report_year</code>, and <code>total_amount</code>.</p>
4242

4343
<p>Return the result table <strong>ordered</strong> by <code>product_id</code> and <code>report_year</code>.</p>
4444

solution/1600-1699/1601.Maximum Number of Achievable Transfer Requests/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Solution {
9292
public int maximumRequests(int n, int[][] requests) {
9393
m = requests.length;
9494
this.n = n;
95-
this.requests = requests;
95+
this.requests = requests;
9696
int ans = 0;
9797
for (int mask = 0; mask < 1 << m; ++mask) {
9898
int cnt = Integer.bitCount(mask);

solution/1700-1799/1751.Maximum Number of Events That Can Be Attended II/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Solution:
115115
j = bisect_right(events, ed, lo=i + 1, key=lambda x: x[0])
116116
ans = max(ans, dfs(j, k - 1) + val)
117117
return ans
118-
118+
119119
events.sort()
120120
return dfs(0, k)
121121
```

solution/2500-2599/2510.Check if There is a Path With Equal Number of 0's And 1's/README.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
# [2510. Check if There is a Path With Equal Number of 0's And 1's](https://leetcode.cn/problems/check-if-there-is-a-path-with-equal-number-of-0s-and-1s)
1+
# [2510. 检查是否有路径经过相同数量的 0 和 1](https://leetcode.cn/problems/check-if-there-is-a-path-with-equal-number-of-0s-and-1s)
22

33
[English Version](/solution/2500-2599/2510.Check%20if%20There%20is%20a%20Path%20With%20Equal%20Number%20of%200%27s%20And%201%27s/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> <strong>binary</strong> matrix <code>grid</code>. You can move from a cell <code>(row, col)</code> to any of the cells <code>(row + 1, col)</code> or <code>(row, col + 1)</code>.</p>
9+
<p>给定一个 <strong>下标从 0 开始</strong> <code>m x n</code> <strong>二进制</strong> 矩阵 <code>grid</code> ,从坐标为 <code>(row, col)</code> 的元素可以向右走 <code>(row, col+1)</code> 或向下走 <code>(row+1, col)</code></p>
1010

11-
<p>Return <code>true</code><em> if there is a path from </em><code>(0, 0)</code><em> to </em><code>(m - 1, n - 1)</code><em> that visits an <strong>equal</strong> number of </em><code>0</code><em>&#39;s and </em><code>1</code><em>&#39;s</em>. Otherwise return <code>false</code>.</p>
11+
<p>返回一个布尔值,表示从 <code>(0, 0)</code> 出发是否存在一条路径,经过 <strong>相同</strong> 数量的 <code>0</code> 和 <code>1</code>,到达终点 <code>(m-1, n-1)</code> 。如果存在这样的路径返回 <code>true</code> ,否则返回 <code>false</code></p>
1212

1313
<p>&nbsp;</p>
14-
<p><strong class="example">Example 1:</strong></p>
14+
15+
<p><strong class="example">示例 1 :</strong></p>
1516
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2500-2599/2510.Check%20if%20There%20is%20a%20Path%20With%20Equal%20Number%20of%200%27s%20And%201%27s/images/yetgriddrawio-4.png" />
1617
<pre>
17-
<strong>Input:</strong> grid = [[0,1,0,0],[0,1,0,0],[1,0,1,0]]
18-
<strong>Output:</strong> true
19-
<strong>Explanation:</strong> The path colored in blue in the above diagram is a valid path because we have 3 cells with a value of 1 and 3 with a value of 0. Since there is a valid path, we return true.
18+
<b>输入:</b>grid = [[0,1,0,0],[0,1,0,0],[1,0,1,0]]
19+
<b>输出:</b>true
20+
<b>解释:</b>以上图中用蓝色标记的路径是一个有效的路径,因为路径上有 3 个值为 1 的单元格和 3 个值为 0 的单元格。由于存在一个有效的路径,因此返回 true
2021
</pre>
2122

22-
<p><strong class="example">Example 2:</strong></p>
23+
<p><strong class="example">示例 2 :</strong></p>
2324
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2500-2599/2510.Check%20if%20There%20is%20a%20Path%20With%20Equal%20Number%20of%200%27s%20And%201%27s/images/yetgrid2drawio-1.png" style="width: 151px; height: 151px;" />
2425
<pre>
25-
<strong>Input:</strong> grid = [[1,1,0],[0,0,1],[1,0,0]]
26-
<strong>Output:</strong> false
27-
<strong>Explanation:</strong> There is no path in this grid with an equal number of 0&#39;s and 1&#39;s.
26+
<b>输入:</b>grid = [[1,1,0],[0,0,1],[1,0,0]]
27+
<b>输出:</b>false
28+
<b>解释:</b>这个网格中没有一条路径经过相等数量的0和1。
2829
</pre>
2930

3031
<p>&nbsp;</p>
31-
<p><strong>Constraints:</strong></p>
32+
33+
<p><strong>提示:</strong></p>
3234

3335
<ul>
3436
<li><code>m == grid.length</code></li>
3537
<li><code>n == grid[i].length</code></li>
3638
<li><code>2 &lt;= m, n &lt;= 100</code></li>
37-
<li><code>grid[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
39+
<li><code>grid[i][j]</code> 不是&nbsp;<code>0</code> 就是&nbsp;<code>1</code></li>
3840
</ul>
3941

4042
## 解法

solution/2500-2599/2519.Count the Number of K-Big Indices/README.md

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1-
# [2519. Count the Number of K-Big Indices](https://leetcode.cn/problems/count-the-number-of-k-big-indices)
1+
# [2519. 统计 K-Big 索引的数量](https://leetcode.cn/problems/count-the-number-of-k-big-indices)
22

33
[English Version](/solution/2500-2599/2519.Count%20the%20Number%20of%20K-Big%20Indices/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and a positive integer <code>k</code>.</p>
9+
<p>给定一个 <strong>下标从0开始</strong> 的整数数组 <code>nums</code> 和一个正整数 <code>k</code></p>
1010

11-
<p>We call an index <code>i</code> <strong>k-big</strong> if the following conditions are satisfied:</p>
11+
<p>如果满足以下条件,我们称下标 <code>i</code> <strong>k-big</strong> </p>
1212

1313
<ul>
14-
<li>There exist at least <code>k</code> different indices <code>idx1</code> such that <code>idx1 &lt; i</code> and <code>nums[idx1] &lt; nums[i]</code>.</li>
15-
<li>There exist at least <code>k</code> different indices <code>idx2</code> such that <code>idx2 &gt; i</code> and <code>nums[idx2] &lt; nums[i]</code>.</li>
14+
<li>存在至少 <code>k</code> 个不同的索引 <code>idx1</code> ,满足 <code>idx1 &lt; i</code> <code>nums[idx1] &lt; nums[i]</code></li>
15+
<li>存在至少 <code>k</code> 个不同的索引 <code>idx2</code> ,满足 <code>idx2 &gt; i</code> <code>nums[idx2] &lt; nums[i]</code></li>
1616
</ul>
1717

18-
<p>Return <em>the number of k-big indices</em>.</p>
18+
<p>返回 k-big 索引的数量。</p>
1919

2020
<p>&nbsp;</p>
21-
<p><strong class="example">Example 1:</strong></p>
21+
22+
<p><strong class="example">示例 1 :</strong></p>
2223

2324
<pre>
24-
<strong>Input:</strong> nums = [2,3,6,5,2,3], k = 2
25-
<strong>Output:</strong> 2
26-
<strong>Explanation:</strong> There are only two 2-big indices in nums:
27-
- i = 2 --&gt; There are two valid idx1: 0 and 1. There are three valid idx2: 2, 3, and 4.
28-
- i = 3 --&gt; There are two valid idx1: 0 and 1. There are two valid idx2: 3 and 4.
29-
</pre>
25+
<b>输入:</b>nums = [2,3,6,5,2,3], k = 2
26+
<b>输出:</b>2
27+
<b>解释:</b>在nums中只有两个 2-big 的索引:
28+
- i = 2 --&gt; 有两个有效的 idx1: 0 和 1。有三个有效的 idx2: 2、3 和 4。
29+
- i = 3 --&gt; 有两个有效的 idx1: 0 和 1。有两个有效的 idx2: 3 和 4。</pre>
3030

31-
<p><strong class="example">Example 2:</strong></p>
31+
<p><strong class="example">示例 2 :</strong></p>
3232

3333
<pre>
34-
<strong>Input:</strong> nums = [1,1,1], k = 3
35-
<strong>Output:</strong> 0
36-
<strong>Explanation:</strong> There are no 3-big indices in nums.
34+
<b>输入:</b>nums = [1,1,1], k = 3
35+
<b>输出:</b>0
36+
<b>解释:</b>在 nums 中没有 3-big 的索引
3737
</pre>
3838

3939
<p>&nbsp;</p>
40-
<p><strong>Constraints:</strong></p>
40+
41+
<p><strong>提示:</strong></p>
4142

4243
<ul>
4344
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>

solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
# [2524. Maximum Frequency Score of a Subarray](https://leetcode.cn/problems/maximum-frequency-score-of-a-subarray)
1+
# [2524. 子数组的最大频率分数](https://leetcode.cn/problems/maximum-frequency-score-of-a-subarray)
22

33
[English Version](/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
9+
<p>给定一个整数数组 <code>nums</code> 和一个 <strong></strong> 整数 <code>k</code></p>
1010

11-
<p>The <strong>frequency score</strong> of an array is the sum of the <strong>distinct</strong> values in the array raised to the power of their <strong>frequencies</strong>, taking the sum <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
11+
<p>数组的 <strong>频率得分</strong> 是数组中 <strong>不同</strong> 值的 <strong>幂次</strong> 之和,并将和对&nbsp;<code>10<sup>9</sup>&nbsp;+ 7</code> <strong>取模</strong>。</p>
1212

13-
<ul>
14-
<li>For example, the frequency score of the array <code>[5,4,5,7,4,4]</code> is <code>(4<sup>3</sup> + 5<sup>2</sup> + 7<sup>1</sup>) modulo (10<sup>9</sup> + 7) = 96</code>.</li>
15-
</ul>
13+
<p>例如,数组 <code>[5,4,5,7,4,4]</code> 的频率得分为 <code>(4<sup>3</sup>&nbsp;+ 5<sup>2</sup>&nbsp;+ 7<sup>1</sup>) modulo (10<sup>9</sup>&nbsp;+ 7) = 96</code> 。</p>
1614

17-
<p>Return <em>the <strong>maximum</strong> frequency score of a <strong>subarray</strong> of size </em><code>k</code><em> in </em><code>nums</code>. You should maximize the value under the modulo and not the actual value.</p>
15+
<p>返回 <code>nums</code> 中长度为 <code>k</code> 的 <strong>子数组</strong> 的 <strong>最大&nbsp;</strong>频率得分。你需要返回取模后的最大值,而不是实际值。</p>
1816

19-
<p>A <strong>subarray</strong> is a contiguous part of an array.</p>
17+
<p><strong>子数组</strong>&nbsp;是一个数组的连续部分。</p>
2018

2119
<p>&nbsp;</p>
22-
<p><strong class="example">Example 1:</strong></p>
20+
21+
<p><strong class="example">示例 1 :</strong></p>
2322

2423
<pre>
25-
<strong>Input:</strong> nums = [1,1,1,2,1,2], k = 3
26-
<strong>Output:</strong> 5
27-
<strong>Explanation:</strong> The subarray [2,1,2] has a frequency score equal to 5. It can be shown that it is the maximum frequency score we can have.
24+
<b>输入:</b>nums = [1,1,1,2,1,2], k = 3
25+
<b>输出:</b>5
26+
<b>解释:</b>子数组 [2,1,2] 的频率分数等于 5。可以证明这是我们可以获得的最大频率分数。
2827
</pre>
2928

30-
<p><strong class="example">Example 2:</strong></p>
29+
<p><strong class="example">示例 2 :</strong></p>
3130

3231
<pre>
33-
<strong>Input:</strong> nums = [1,1,1,1,1,1], k = 4
34-
<strong>Output:</strong> 1
35-
<strong>Explanation:</strong> All the subarrays of length 4 have a frequency score equal to 1.
32+
<b>输入:</b>nums = [1,1,1,1,1,1], k = 4
33+
<b>输出:</b>1
34+
<b>解释:</b>所有长度为 4 的子数组的频率得分都等于 1。
3635
</pre>
3736

3837
<p>&nbsp;</p>
39-
<p><strong>Constraints:</strong></p>
38+
39+
<p><strong>提示:</strong></p>
4040

4141
<ul>
4242
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>

0 commit comments

Comments
 (0)