Skip to content

Commit 2e2196e

Browse files
committed
feat: add solutions to lc problems: No.2520~2523
* No.2520.Count the Digits That Divide a Number * No.2521.Distinct Prime Factors of Product of Array * No.2522.Partition String Into Substrings With Values at Most K * No.2523.Closest Prime Numbers in Range
1 parent 7440cfa commit 2e2196e

File tree

64 files changed

+2552
-688
lines changed

Some content is hidden

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

64 files changed

+2552
-688
lines changed

solution/0000-0099/0053.Maximum Subarray/README_EN.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@
44

55
## Description
66

7-
<p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> which has the largest sum and return <em>its sum</em>.</p>
7+
<p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
88

99
<p>&nbsp;</p>
1010
<p><strong class="example">Example 1:</strong></p>
1111

1212
<pre>
1313
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
1414
<strong>Output:</strong> 6
15-
<strong>Explanation:</strong> [4,-1,2,1] has the largest sum = 6.
15+
<strong>Explanation:</strong> The subarray [4,-1,2,1] has the largest sum 6.
1616
</pre>
1717

1818
<p><strong class="example">Example 2:</strong></p>
1919

2020
<pre>
2121
<strong>Input:</strong> nums = [1]
2222
<strong>Output:</strong> 1
23+
<strong>Explanation:</strong> The subarray [1] has the largest sum 1.
2324
</pre>
2425

2526
<p><strong class="example">Example 3:</strong></p>
2627

2728
<pre>
2829
<strong>Input:</strong> nums = [5,4,-1,7,8]
2930
<strong>Output:</strong> 23
31+
<strong>Explanation:</strong> The subarray [5,4,-1,7,8] has the largest sum 23.
3032
</pre>
3133

3234
<p>&nbsp;</p>

solution/0000-0099/0074.Search a 2D Matrix/README_EN.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
## Description
66

7-
<p>Write an efficient algorithm that searches for a value <code>target</code> in an <code>m x n</code> integer matrix <code>matrix</code>. This matrix has the following properties:</p>
7+
<p>You are given an <code>m x n</code> integer matrix <code>matrix</code> with the following two properties:</p>
88

99
<ul>
10-
<li>Integers in each row are sorted from left to right.</li>
10+
<li>Each row is sorted in non-decreasing order.</li>
1111
<li>The first integer of each row is greater than the last integer of the previous row.</li>
1212
</ul>
1313

14+
<p>Given an integer <code>target</code>, return <code>true</code> <em>if</em> <code>target</code> <em>is in</em> <code>matrix</code> <em>or</em> <code>false</code> <em>otherwise</em>.</p>
15+
16+
<p>You must write a solution in <code>O(log(m * n))</code> time complexity.</p>
17+
1418
<p>&nbsp;</p>
1519
<p><strong class="example">Example 1:</strong></p>
1620
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0074.Search%20a%202D%20Matrix/images/mat.jpg" style="width: 322px; height: 242px;" />

solution/0200-0299/0239.Sliding Window Maximum/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ func maxSlidingWindow(nums []int, k int) (ans []int) {
221221
}
222222
```
223223

224-
225224
### **JavaScript**
226225

227226
```js

solution/0400-0499/0416.Partition Equal Subset Sum/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>Given a <strong>non-empty</strong> array <code>nums</code> containing <strong>only positive integers</strong>, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.</p>
7+
<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
88

99
<p>&nbsp;</p>
1010
<p><strong class="example">Example 1:</strong></p>

solution/0800-0899/0855.Exam Room/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ExamRoom {
122122
this.n = n;
123123
add(new int[] {-1, n});
124124
}
125-
125+
126126
public int seat() {
127127
int[] s = ts.first();
128128
int p = (s[0] + s[1]) >> 1;
@@ -136,7 +136,7 @@ class ExamRoom {
136136
add(new int[] {p, s[1]});
137137
return p;
138138
}
139-
139+
140140
public void leave(int p) {
141141
int l = left.get(p), r = right.get(p);
142142
del(new int[] {l, p});
@@ -195,7 +195,7 @@ public:
195195
this->n = n;
196196
add({-1, n});
197197
}
198-
198+
199199
int seat() {
200200
auto s = *ts.begin();
201201
int p = (s.first + s.second) >> 1;
@@ -209,7 +209,7 @@ public:
209209
add({p, s.second});
210210
return p;
211211
}
212-
212+
213213
void leave(int p) {
214214
int l = left[p], r = right[p];
215215
del({l, p});

solution/0800-0899/0886.Possible Bipartition/README_EN.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@
1414
<pre>
1515
<strong>Input:</strong> n = 4, dislikes = [[1,2],[1,3],[2,4]]
1616
<strong>Output:</strong> true
17-
<strong>Explanation:</strong> group1 [1,4] and group2 [2,3].
17+
<strong>Explanation:</strong> The first group has [1,4], and the second group has [2,3].
1818
</pre>
1919

2020
<p><strong class="example">Example 2:</strong></p>
2121

2222
<pre>
2323
<strong>Input:</strong> n = 3, dislikes = [[1,2],[1,3],[2,3]]
2424
<strong>Output:</strong> false
25-
</pre>
26-
27-
<p><strong class="example">Example 3:</strong></p>
28-
29-
<pre>
30-
<strong>Input:</strong> n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]
31-
<strong>Output:</strong> false
25+
<strong>Explanation:</strong> We need at least 3 groups to divide them. We cannot put them in two groups.
3226
</pre>
3327

3428
<p>&nbsp;</p>
@@ -38,8 +32,7 @@
3832
<li><code>1 &lt;= n &lt;= 2000</code></li>
3933
<li><code>0 &lt;= dislikes.length &lt;= 10<sup>4</sup></code></li>
4034
<li><code>dislikes[i].length == 2</code></li>
41-
<li><code>1 &lt;= dislikes[i][j] &lt;= n</code></li>
42-
<li><code>a<sub>i</sub> &lt; b<sub>i</sub></code></li>
35+
<li><code>1 &lt;= a<sub>i</sub> &lt; b<sub>i</sub> &lt;= n</code></li>
4336
<li>All the pairs of <code>dislikes</code> are <strong>unique</strong>.</li>
4437
</ul>
4538

solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README_EN.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,33 @@
66

77
<p><strong>No-Zero integer</strong> is a positive integer that <strong>does not contain any <code>0</code></strong> in its decimal representation.</p>
88

9-
<p>Given an integer <code>n</code>, return <em>a list of two integers</em> <code>[A, B]</code> <em>where</em>:</p>
9+
<p>Given an integer <code>n</code>, return <em>a list of two integers</em> <code>[a, b]</code> <em>where</em>:</p>
1010

1111
<ul>
12-
<li><code>A</code> and <code>B</code> are <strong>No-Zero integers</strong>.</li>
13-
<li><code>A + B = n</code></li>
12+
<li><code>a</code> and <code>b</code> are <strong>No-Zero integers</strong>.</li>
13+
<li><code>a + b = n</code></li>
1414
</ul>
1515

16-
<p>The test cases are generated so that there is at least one valid solution. If there are many valid solutions you can return any of them.</p>
16+
<p>The test cases are generated so that there is at least one valid solution. If there are many valid solutions, you can return any of them.</p>
1717

1818
<p>&nbsp;</p>
1919
<p><strong class="example">Example 1:</strong></p>
2020

2121
<pre>
2222
<strong>Input:</strong> n = 2
2323
<strong>Output:</strong> [1,1]
24-
<strong>Explanation:</strong> A = 1, B = 1. A + B = n and both A and B do not contain any 0 in their decimal representation.
24+
<strong>Explanation:</strong> Let a = 1 and b = 1.
25+
Both a and b are no-zero integers, and a + b = 2 = n.
2526
</pre>
2627

2728
<p><strong class="example">Example 2:</strong></p>
2829

2930
<pre>
3031
<strong>Input:</strong> n = 11
3132
<strong>Output:</strong> [2,9]
33+
<strong>Explanation:</strong> Let a = 2 and b = 9.
34+
Both a and b are no-zero integers, and a + b = 9 = n.
35+
Note that there are other valid answers as [8, 3] that can be accepted.
3236
</pre>
3337

3438
<p>&nbsp;</p>

solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Pick the number 20 and reduce it to 10.
3636
Pick the number 10 and reduce it to 5.
3737
Pick the number 3 and reduce it to 1.5.
3838
The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5.
39-
The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 &gt;= 31/2 = 16.5.
39+
The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 &gt;= 31/2 = 15.5.
4040
Overall, 3 operations were used so we return 3.
4141
It can be shown that we cannot reduce the sum by at least half in less than 3 operations.
4242
</pre>

solution/2300-2399/2355.Maximum Number of Books You Can Take/README.md

+36-34
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,63 @@
1-
# [2355. Maximum Number of Books You Can Take](https://leetcode.cn/problems/maximum-number-of-books-you-can-take)
1+
# [2355. 你能拿走的最大图书数量](https://leetcode.cn/problems/maximum-number-of-books-you-can-take)
22

33
[English Version](/solution/2300-2399/2355.Maximum%20Number%20of%20Books%20You%20Can%20Take/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>You are given a <strong>0-indexed</strong> integer array <code>books</code> of length <code>n</code> where <code>books[i]</code> denotes the number of books on the <code>i<sup>th</sup></code> shelf of a bookshelf.</p>
9+
<p>给定一个长度为 <code>n</code> 的<b>&nbsp;下标从 0 开始&nbsp;</b>的整数数组 <code>books</code>,其中 <code>books[i]</code> 表示书架的第 <code>i</code> 个书架上的书的数量。</p>
1010

11-
<p>You are going to take books from a <strong>contiguous</strong> section of the bookshelf spanning from <code>l</code> to <code>r</code> where <code>0 &lt;= l &lt;= r &lt; n</code>. For each index <code>i</code> in the range <code>l &lt;= i &lt; r</code>, you must take <strong>strictly fewer</strong> books from shelf <code>i</code> than shelf <code>i + 1</code>.</p>
11+
<p>你要从书架&nbsp;<code>l</code> 到 <code>r</code> 的一个&nbsp;<strong>连续&nbsp;</strong>的部分中取书,其中 <code>0 &lt;= l &lt;= r &lt; n</code>。对于 <code>l &lt;= i &lt; r</code> 范围内的每个索引 <code>i</code>,你从书架 <code>i</code>&nbsp;取书的数量必须&nbsp;<strong>严格小于 </strong>你从书架 <code>i + 1</code> 取书的数量。</p>
1212

13-
<p>Return <em>the <strong>maximum</strong> number of books you can take from the bookshelf.</em></p>
13+
<p>返回<em>你能从书架上拿走的书的&nbsp;<strong>最大&nbsp;</strong>数量。</em></p>
1414

1515
<p>&nbsp;</p>
16-
<p><strong class="example">Example 1:</strong></p>
16+
17+
<p><strong>示例 1:</strong></p>
1718

1819
<pre>
19-
<strong>Input:</strong> books = [8,5,2,7,9]
20-
<strong>Output:</strong> 19
21-
<strong>Explanation:</strong>
22-
- Take 1 book from shelf 1.
23-
- Take 2 books from shelf 2.
24-
- Take 7 books from shelf 3.
25-
- Take 9 books from shelf 4.
26-
You have taken 19 books, so return 19.
27-
It can be proven that 19 is the maximum number of books you can take.
20+
<strong>输入:</strong> books = [8,5,2,7,9]
21+
<strong>输出:</strong> 19
22+
<strong>解释:</strong>
23+
- 从书架 1 上取 1 本书。
24+
- 从书架 2 上取 2 本书。
25+
- 从书架 3 上取 7 本书
26+
- 从书架 4 上取 9 本书
27+
你已经拿了19本书,所以返回 19。
28+
可以证明 19 本是你所能拿走的书的最大数量。
2829
</pre>
2930

30-
<p><strong class="example">Example 2:</strong></p>
31+
<p><strong>示例&nbsp;2:</strong></p>
3132

3233
<pre>
33-
<strong>Input:</strong> books = [7,0,3,4,5]
34-
<strong>Output:</strong> 12
35-
<strong>Explanation:</strong>
36-
- Take 3 books from shelf 2.
37-
- Take 4 books from shelf 3.
38-
- Take 5 books from shelf 4.
39-
You have taken 12 books so return 12.
40-
It can be proven that 12 is the maximum number of books you can take.
34+
<strong>输入:</strong> books = [7,0,3,4,5]
35+
<strong>输出:</strong> 12
36+
<strong>解释:</strong>
37+
- 从书架 2 上取 3 本书。
38+
- 从书架 3 上取 4 本书。
39+
- 从书架 4 上取 5 本书。
40+
你已经拿了 12 本书,所以返回 12。
41+
可以证明 12 本是你所能拿走的书的最大数量。
4142
</pre>
4243

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

4546
<pre>
46-
<strong>Input:</strong> books = [8,2,3,7,3,4,0,1,4,3]
47-
<strong>Output:</strong> 13
48-
<strong>Explanation:</strong>
49-
- Take 1 book from shelf 0.
50-
- Take 2 books from shelf 1.
51-
- Take 3 books from shelf 2.
52-
- Take 7 books from shelf 3.
53-
You have taken 13 books so return 13.
54-
It can be proven that 13 is the maximum number of books you can take.
47+
<strong>输入:</strong> books = [8,2,3,7,3,4,0,1,4,3]
48+
<strong>输出:</strong> 13
49+
<strong>解释:</strong>
50+
- 从书架 0 上取 1 本书。
51+
- 从书架 1 上取 2 本书。
52+
- 从书架 2 上取 3 本书。
53+
- 从书架 3 上取 7 本书。
54+
你已经拿了 13 本书,所以返回 13。
55+
可以证明 13 本是你所能拿走的书的最大数量。
5556
</pre>
5657

5758
<p>&nbsp;</p>
58-
<p><strong>Constraints:</strong></p>
59+
60+
<p><strong>提示:</strong></p>
5961

6062
<ul>
6163
<li><code>1 &lt;= books.length &lt;= 10<sup>5</sup></code></li>

solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# [2356. Number of Unique Subjects Taught by Each Teacher](https://leetcode.cn/problems/number-of-unique-subjects-taught-by-each-teacher)
1+
# [2356. 每位教师所教授的科目种类的数量](https://leetcode.cn/problems/number-of-unique-subjects-taught-by-each-teacher)
22

33
[English Version](/solution/2300-2399/2356.Number%20of%20Unique%20Subjects%20Taught%20by%20Each%20Teacher/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>Table: <code>Teacher</code></p>
9+
<p>: <code>Teacher</code></p>
1010

1111
<pre>
1212
+-------------+------+
@@ -16,24 +16,25 @@
1616
| subject_id | int |
1717
| dept_id | int |
1818
+-------------+------+
19-
(subject_id, dept_id) is the primary key for this table.
20-
Each row in this table indicates that the teacher with teacher_id teaches the subject subject_id in the department dept_id.
19+
(subject_id, dept_id) 是该表的主键。
20+
该表中的每一行都表示带有 teacher_id 的教师在系 dept_id 中教授科目 subject_id
2121
</pre>
2222

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

25-
<p>Write an SQL query to report the number of unique subjects each teacher teaches in the university.</p>
25+
<p>写一个 SQL 来查询每位老师在大学里教授的科目种类的数量。</p>
2626

27-
<p>Return the result table in <strong>any order</strong>.</p>
27+
<p data-group="1-1">以 <strong>任意顺序</strong> 返回结果表。</p>
2828

29-
<p>The query result format is shown in the following example.</p>
29+
<p>查询结果格式示例如下。</p>
3030

3131
<p>&nbsp;</p>
32-
<p><strong class="example">Example 1:</strong></p>
32+
33+
<p><strong>示例 1:</strong></p>
3334

3435
<pre>
35-
<strong>Input:</strong>
36-
Teacher table:
36+
<strong>输入:</strong>
37+
Teacher :
3738
+------------+------------+---------+
3839
| teacher_id | subject_id | dept_id |
3940
+------------+------------+---------+
@@ -45,23 +46,22 @@ Teacher table:
4546
| 2 | 3 | 1 |
4647
| 2 | 4 | 1 |
4748
+------------+------------+---------+
48-
<strong>Output:</strong>
49+
<strong>输出:</strong>
4950
+------------+-----+
5051
| teacher_id | cnt |
5152
+------------+-----+
5253
| 1 | 2 |
5354
| 2 | 4 |
5455
+------------+-----+
55-
<strong>Explanation:</strong>
56-
Teacher 1:
57-
- They teach subject 2 in departments 3 and 4.
58-
- They teach subject 3 in department 3.
59-
Teacher 2:
60-
- They teach subject 1 in department 1.
61-
- They teach subject 2 in department 1.
62-
- They teach subject 3 in department 1.
63-
- They teach subject 4 in department 1.
64-
</pre>
56+
<strong>解释:</strong>
57+
教师 1:
58+
- 他在 3、4 系教科目 2。
59+
- 他在 3 系教科目 3。
60+
教师 2:
61+
- 他在 1 系教科目 1。
62+
- 他在 1 系教科目 2。
63+
- 他在 1 系教科目 3。
64+
- 他在 1 系教科目 4。</pre>
6565

6666
## 解法
6767

0 commit comments

Comments
 (0)