Skip to content

Commit 15f7077

Browse files
authored
feat: add new lc problems (#4453)
1 parent 8c4bba2 commit 15f7077

File tree

22 files changed

+1506
-11
lines changed

22 files changed

+1506
-11
lines changed

solution/0500-0599/0596.Classes More Than 5 Students/README.md renamed to solution/0500-0599/0596.Classes With at Least 5 Students/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
comments: true
33
difficulty: 简单
4-
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README.md
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README.md
55
tags:
66
- 数据库
77
---
88

99
<!-- problem:start -->
1010

11-
# [596. 超过 5 名学生的课](https://leetcode.cn/problems/classes-more-than-5-students)
11+
# [596. 超过 5 名学生的课](https://leetcode.cn/problems/classes-with-at-least-5-students)
1212

13-
[English Version](/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README_EN.md)
13+
[English Version](/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README_EN.md)
1414

1515
## 题目描述
1616

solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md renamed to solution/0500-0599/0596.Classes With at Least 5 Students/README_EN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
comments: true
33
difficulty: Easy
4-
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README_EN.md
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README_EN.md
55
tags:
66
- Database
77
---
88

99
<!-- problem:start -->
1010

11-
# [596. Classes More Than 5 Students](https://leetcode.com/problems/classes-more-than-5-students)
11+
# [596. Classes With at Least 5 Students](https://leetcode.com/problems/classes-with-at-least-5-students)
1212

13-
[中文文档](/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README.md)
13+
[中文文档](/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README.md)
1414

1515
## Description
1616

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3566.Partition%20Array%20into%20Two%20Equal%20Product%20Subsets/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3566. 等积子集的划分方案](https://leetcode.cn/problems/partition-array-into-two-equal-product-subsets)
10+
11+
[English Version](/solution/3500-3599/3566.Partition%20Array%20into%20Two%20Equal%20Product%20Subsets/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个整数数组 <code>nums</code>,其中包含的正整数&nbsp;<strong>互不相同&nbsp;</strong>,另给你一个整数 <code>target</code>。</p>
18+
19+
<p>请判断是否可以将 <code>nums</code> 分成两个&nbsp;<strong>非空</strong>、<strong>互不相交&nbsp;</strong>的&nbsp;<strong>子集&nbsp;</strong>,并且每个元素必须 &nbsp;<strong>恰好 </strong>属于&nbsp;<strong>一个&nbsp;</strong>子集,使得这两个子集中元素的乘积都等于 <code>target</code>。</p>
20+
21+
<p>如果存在这样的划分,返回 <code>true</code>;否则,返回 <code>false</code>。</p>
22+
23+
<p><strong>子集&nbsp;</strong>是数组中元素的一个选择集合。</p>
24+
25+
<p>&nbsp;</p>
26+
27+
<p><strong class="example">示例 1:</strong></p>
28+
29+
<div class="example-block">
30+
<p><strong>输入:</strong> <span class="example-io">nums = [3,1,6,8,4], target = 24</span></p>
31+
32+
<p><strong>输出:</strong> <span class="example-io">true</span></p>
33+
34+
<p><strong>解释:</strong>子集 <code>[3, 8]</code> 和 <code>[1, 6, 4]</code> 的乘积均为 24。因此,输出为 true 。</p>
35+
</div>
36+
37+
<p><strong class="example">示例 2:</strong></p>
38+
39+
<div class="example-block">
40+
<p><strong>输入:</strong> <span class="example-io">nums = [2,5,3,7], target = 15</span></p>
41+
42+
<p><strong>输出:</strong> <span class="example-io">false</span></p>
43+
44+
<p><strong>解释:</strong>无法将 <code>nums</code> 划分为两个非空的互不相交子集,使得它们的乘积均为 15。因此,输出为 false。</p>
45+
</div>
46+
47+
<p>&nbsp;</p>
48+
49+
<p><strong>提示:</strong></p>
50+
51+
<ul>
52+
<li><code>3 &lt;= nums.length &lt;= 12</code></li>
53+
<li><code>1 &lt;= target &lt;= 10<sup>15</sup></code></li>
54+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
55+
<li><code>nums</code> 中的所有元素互不相同。</li>
56+
</ul>
57+
58+
<!-- description:end -->
59+
60+
## 解法
61+
62+
<!-- solution:start -->
63+
64+
### 方法一
65+
66+
<!-- tabs:start -->
67+
68+
#### Python3
69+
70+
```python
71+
72+
```
73+
74+
#### Java
75+
76+
```java
77+
78+
```
79+
80+
#### C++
81+
82+
```cpp
83+
84+
```
85+
86+
#### Go
87+
88+
```go
89+
90+
```
91+
92+
<!-- tabs:end -->
93+
94+
<!-- solution:end -->
95+
96+
<!-- problem:end -->
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
comments: true
3+
difficulty: Medium
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3566.Partition%20Array%20into%20Two%20Equal%20Product%20Subsets/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3566. Partition Array into Two Equal Product Subsets](https://leetcode.com/problems/partition-array-into-two-equal-product-subsets)
10+
11+
[中文文档](/solution/3500-3599/3566.Partition%20Array%20into%20Two%20Equal%20Product%20Subsets/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an integer array <code>nums</code> containing <strong>distinct</strong> positive integers and an integer <code>target</code>.</p>
18+
19+
<p>Determine if you can partition <code>nums</code> into two <strong>non-empty</strong> <strong>disjoint</strong> <strong>subsets</strong>, with each element belonging to <strong>exactly one</strong> subset, such that the product of the elements in each subset is equal to <code>target</code>.</p>
20+
21+
<p>Return <code>true</code> if such a partition exists and <code>false</code> otherwise.</p>
22+
A <strong>subset</strong> of an array is a selection of elements of the array.
23+
<p>&nbsp;</p>
24+
<p><strong class="example">Example 1:</strong></p>
25+
26+
<div class="example-block">
27+
<p><strong>Input:</strong> <span class="example-io">nums = [3,1,6,8,4], target = 24</span></p>
28+
29+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
30+
31+
<p><strong>Explanation:</strong> The subsets <code>[3, 8]</code> and <code>[1, 6, 4]</code> each have a product of 24. Hence, the output is true.</p>
32+
</div>
33+
34+
<p><strong class="example">Example 2:</strong></p>
35+
36+
<div class="example-block">
37+
<p><strong>Input:</strong> <span class="example-io">nums = [2,5,3,7], target = 15</span></p>
38+
39+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
40+
41+
<p><strong>Explanation:</strong> There is no way to partition <code>nums</code> into two non-empty disjoint subsets such that both subsets have a product of 15. Hence, the output is false.</p>
42+
</div>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>3 &lt;= nums.length &lt;= 12</code></li>
49+
<li><code>1 &lt;= target &lt;= 10<sup>15</sup></code></li>
50+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
51+
<li>All elements of <code>nums</code> are <strong>distinct</strong>.</li>
52+
</ul>
53+
54+
<!-- description:end -->
55+
56+
## Solutions
57+
58+
<!-- solution:start -->
59+
60+
### Solution 1
61+
62+
<!-- tabs:start -->
63+
64+
#### Python3
65+
66+
```python
67+
68+
```
69+
70+
#### Java
71+
72+
```java
73+
74+
```
75+
76+
#### C++
77+
78+
```cpp
79+
80+
```
81+
82+
#### Go
83+
84+
```go
85+
86+
```
87+
88+
<!-- tabs:end -->
89+
90+
<!-- solution:end -->
91+
92+
<!-- problem:end -->
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3567.Minimum%20Absolute%20Difference%20in%20Sliding%20Submatrix/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3567. 子矩阵的最小绝对差](https://leetcode.cn/problems/minimum-absolute-difference-in-sliding-submatrix)
10+
11+
[English Version](/solution/3500-3599/3567.Minimum%20Absolute%20Difference%20in%20Sliding%20Submatrix/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个 <code>m x n</code> 的整数矩阵 <code>grid</code> 和一个整数 <code>k</code>。</p>
18+
19+
<p>对于矩阵 <code>grid</code> 中的每个连续的 <code>k x k</code> <strong>子矩阵</strong>,计算其中任意两个&nbsp;<strong>不同</strong>值 之间的&nbsp;<strong>最小绝对差&nbsp;</strong>。</p>
20+
21+
<p>返回一个大小为 <code>(m - k + 1) x (n - k + 1)</code> 的二维数组 <code>ans</code>,其中 <code>ans[i][j]</code> 表示以 <code>grid</code> 中坐标 <code>(i, j)</code> 为左上角的子矩阵的最小绝对差。</p>
22+
23+
<p><strong>注意</strong>:如果子矩阵中的所有元素都相同,则答案为 0。</p>
24+
25+
<p>子矩阵 <code>(x1, y1, x2, y2)</code> 是一个由选择矩阵中所有满足 <code>x1 &lt;= x &lt;= x2</code> 且 <code>y1 &lt;= y &lt;= y2</code> 的单元格 <code>matrix[x][y]</code> 组成的矩阵。</p>
26+
27+
<p>&nbsp;</p>
28+
29+
<p><strong class="example">示例 1:</strong></p>
30+
31+
<div class="example-block">
32+
<p><strong>输入:</strong> <span class="example-io">grid = [[1,8],[3,-2]], k = 2</span></p>
33+
34+
<p><strong>输出:</strong> <span class="example-io">[[2]]</span></p>
35+
36+
<p><strong>解释:</strong></p>
37+
38+
<ul>
39+
<li>只有一个可能的 <code>k x k</code> 子矩阵:<code><span class="example-io">[[1, 8], [3, -2]]</span></code>。</li>
40+
<li>子矩阵中的不同值为 <code>[1, 8, 3, -2]</code>。</li>
41+
<li>子矩阵中的最小绝对差为 <code>|1 - 3| = 2</code>。因此,答案为 <code>[[2]]</code>。</li>
42+
</ul>
43+
</div>
44+
45+
<p><strong class="example">示例 2:</strong></p>
46+
47+
<div class="example-block">
48+
<p><strong>输入:</strong> <span class="example-io">grid = [[3,-1]], k = 1</span></p>
49+
50+
<p><strong>输出:</strong> <span class="example-io">[[0,0]]</span></p>
51+
52+
<p><strong>解释:</strong></p>
53+
54+
<ul>
55+
<li>每个 <code>k x k</code> 子矩阵中只有一个不同的元素。</li>
56+
<li>因此,答案为 <code>[[0, 0]]</code>。</li>
57+
</ul>
58+
</div>
59+
60+
<p><strong class="example">示例 3:</strong></p>
61+
62+
<div class="example-block">
63+
<p><strong>输入:</strong> <span class="example-io">grid = [[1,-2,3],[2,3,5]], k = 2</span></p>
64+
65+
<p><strong>输出:</strong> <span class="example-io">[[1,2]]</span></p>
66+
67+
<p><strong>解释:</strong></p>
68+
69+
<ul>
70+
<li>有两个可能的 <code>k × k</code> 子矩阵:
71+
72+
<ul>
73+
<li>以 <code>(0, 0)</code> 为起点的子矩阵:<code>[[1, -2], [2, 3]]</code>。
74+
75+
<ul>
76+
<li>子矩阵中的不同值为 <code>[1, -2, 2, 3]</code>。</li>
77+
<li>子矩阵中的最小绝对差为 <code>|1 - 2| = 1</code>。</li>
78+
</ul>
79+
</li>
80+
<li>以 <code>(0, 1)</code> 为起点的子矩阵:<code>[[-2, 3], [3, 5]]</code>。
81+
<ul>
82+
<li>子矩阵中的不同值为 <code>[-2, 3, 5]</code>。</li>
83+
<li>子矩阵中的最小绝对差为 <code>|3 - 5| = 2</code>。</li>
84+
</ul>
85+
</li>
86+
</ul>
87+
</li>
88+
<li>因此,答案为 <code>[[1, 2]]</code>。</li>
89+
90+
</ul>
91+
</div>
92+
93+
<p>&nbsp;</p>
94+
95+
<p><strong>提示:</strong></p>
96+
97+
<ul>
98+
<li><code>1 &lt;= m == grid.length &lt;= 30</code></li>
99+
<li><code>1 &lt;= n == grid[i].length &lt;= 30</code></li>
100+
<li><code>-10<sup>5</sup> &lt;= grid[i][j] &lt;= 10<sup>5</sup></code></li>
101+
<li><code>1 &lt;= k &lt;= min(m, n)</code></li>
102+
</ul>
103+
104+
<!-- description:end -->
105+
106+
## 解法
107+
108+
<!-- solution:start -->
109+
110+
### 方法一
111+
112+
<!-- tabs:start -->
113+
114+
#### Python3
115+
116+
```python
117+
118+
```
119+
120+
#### Java
121+
122+
```java
123+
124+
```
125+
126+
#### C++
127+
128+
```cpp
129+
130+
```
131+
132+
#### Go
133+
134+
```go
135+
136+
```
137+
138+
<!-- tabs:end -->
139+
140+
<!-- solution:end -->
141+
142+
<!-- problem:end -->

0 commit comments

Comments
 (0)