Skip to content

Commit 1119b77

Browse files
committed
feat: add new lc problems
1 parent 8c4bba2 commit 1119b77

File tree

21 files changed

+1684
-1
lines changed

21 files changed

+1684
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README.md
5+
tags:
6+
- 数据库
7+
---
8+
9+
<!-- problem:start -->
10+
11+
# [596. 超过 5 名学生的课](https://leetcode.cn/problems/classes-with-at-least-5-students)
12+
13+
[English Version](/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README_EN.md)
14+
15+
## 题目描述
16+
17+
<!-- description:start -->
18+
19+
<p>表:&nbsp;<code>Courses</code></p>
20+
21+
<pre>
22+
+-------------+---------+
23+
| Column Name | Type |
24+
+-------------+---------+
25+
| student | varchar |
26+
| class | varchar |
27+
+-------------+---------+
28+
(student, class)是该表的主键(不同值的列的组合)。
29+
该表的每一行表示学生的名字和他们注册的班级。
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
34+
<p>查询&nbsp;<strong>至少有 5 个学生</strong> 的所有班级。</p>
35+
36+
<p>以 <strong>任意顺序 </strong>返回结果表。</p>
37+
38+
<p>结果格式如下所示。</p>
39+
40+
<p>&nbsp;</p>
41+
42+
<p><strong class="example">示例 1:</strong></p>
43+
44+
<pre>
45+
<strong>输入:</strong>
46+
Courses table:
47+
+---------+----------+
48+
| student | class |
49+
+---------+----------+
50+
| A | Math |
51+
| B | English |
52+
| C | Math |
53+
| D | Biology |
54+
| E | Math |
55+
| F | Computer |
56+
| G | Math |
57+
| H | Math |
58+
| I | Math |
59+
+---------+----------+
60+
<strong>输出:</strong>
61+
+---------+
62+
| class &nbsp; |
63+
+---------+
64+
| Math &nbsp; &nbsp;|
65+
+---------+
66+
<strong>解释: </strong>
67+
-数学课有 6 个学生,所以我们包括它。
68+
-英语课有 1 名学生,所以我们不包括它。
69+
-生物课有 1 名学生,所以我们不包括它。
70+
-计算机课有 1 个学生,所以我们不包括它。</pre>
71+
72+
<!-- description:end -->
73+
74+
## 解法
75+
76+
<!-- solution:start -->
77+
78+
### 方法一
79+
80+
<!-- tabs:start -->
81+
82+
#### MySQL
83+
84+
```sql
85+
86+
```
87+
88+
<!-- tabs:end -->
89+
90+
<!-- solution:end -->
91+
92+
<!-- 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: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README_EN.md
5+
tags:
6+
- Database
7+
---
8+
9+
<!-- problem:start -->
10+
11+
# [596. Classes With at Least 5 Students](https://leetcode.com/problems/classes-with-at-least-5-students)
12+
13+
[中文文档](/solution/0500-0599/0596.Classes%20With%20at%20Least%205%20Students/README.md)
14+
15+
## Description
16+
17+
<!-- description:start -->
18+
19+
<p>Table: <code>Courses</code></p>
20+
21+
<pre>
22+
+-------------+---------+
23+
| Column Name | Type |
24+
+-------------+---------+
25+
| student | varchar |
26+
| class | varchar |
27+
+-------------+---------+
28+
(student, class) is the primary key (combination of columns with unique values) for this table.
29+
Each row of this table indicates the name of a student and the class in which they are enrolled.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
34+
<p>Write a solution to find all the classes that have <strong>at least five students</strong>.</p>
35+
36+
<p>Return the result table in <strong>any order</strong>.</p>
37+
38+
<p>The&nbsp;result format is in the following example.</p>
39+
40+
<p>&nbsp;</p>
41+
<p><strong class="example">Example 1:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong>
45+
Courses table:
46+
+---------+----------+
47+
| student | class |
48+
+---------+----------+
49+
| A | Math |
50+
| B | English |
51+
| C | Math |
52+
| D | Biology |
53+
| E | Math |
54+
| F | Computer |
55+
| G | Math |
56+
| H | Math |
57+
| I | Math |
58+
+---------+----------+
59+
<strong>Output:</strong>
60+
+---------+
61+
| class |
62+
+---------+
63+
| Math |
64+
+---------+
65+
<strong>Explanation:</strong>
66+
- Math has 6 students, so we include it.
67+
- English has 1 student, so we do not include it.
68+
- Biology has 1 student, so we do not include it.
69+
- Computer has 1 student, so we do not include it.
70+
</pre>
71+
72+
<!-- description:end -->
73+
74+
## Solutions
75+
76+
<!-- solution:start -->
77+
78+
### Solution 1
79+
80+
<!-- tabs:start -->
81+
82+
#### MySQL
83+
84+
```sql
85+
86+
```
87+
88+
<!-- tabs:end -->
89+
90+
<!-- solution:end -->
91+
92+
<!-- problem:end -->
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 -->

0 commit comments

Comments
 (0)