Skip to content

Commit e884d11

Browse files
committed
feat: add new lc problems and update main script
1 parent 0268b5d commit e884d11

File tree

19 files changed

+1012
-33
lines changed

19 files changed

+1012
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# [1950. 所有子数组最小值中的最大值](https://leetcode-cn.com/problems/maximum-of-minimum-values-in-all-subarrays)
2+
3+
[English Version](/solution/1900-1999/1950.Maximum%20of%20Minimum%20Values%20in%20All%20Subarrays/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code> ,你需要处理 <code>n</code> 个查询。对于第 <code>i</code> (<code>0 <= i < n</code>)个查询,你需要先找出 <code>nums</code> 的所有长度为 <code>i + 1</code> 的子数组中的<strong> 最小值</strong> ,在这些最小值中找出<strong> 最大值</strong> 作为答案。</p>
10+
11+
<p>返回一个 <strong>下标从 0 开始</strong> 的长度为 <code>n</code> 的整数数组 <code>ans</code> ,<code>ans[i]</code> 代表第 <code>i</code> 个查询的答案。</p>
12+
13+
<p> </p>
14+
15+
<p><strong>示例 1:</strong></p>
16+
17+
<pre>
18+
<strong>输入:</strong> nums = [10,20,50,10]
19+
<strong>输出:</strong> [50,20,10,10]
20+
<strong>解释:</strong>
21+
大小为1的子数组为[0], [1], [2], [4]
22+
有最大的最小值的子数组是 [4], 它的最小值是4
23+
大小为2的子数组为[0,1], [1,2], [2,4]
24+
有最大的最小值的子数组是 [2,4], 它的最小值是2
25+
大小为3的子数组为[0,1,2], [1,2,4]
26+
有最大的最小值的子数组是 [1,2,4], 它的最小值是1
27+
大小为4的子数组为[0,1,2,4]
28+
有最大的最小值的子数组是 [0,1,2,4], 它的最小值是0</pre>
29+
30+
<p><strong>示例 2:</strong></p>
31+
32+
<pre>
33+
<strong>输入: </strong>nums = [10,20,50,10]
34+
<strong>输出: </strong>[50,20,10,10]
35+
<strong>解释:</strong>
36+
大小为1的子数组为[10], [20], [50], [10]
37+
有最大的最小值的子数组是 [50], 它的最小值是50
38+
大小为2的子数组为[10,20], [20,50], [50,10]
39+
有最大的最小值的子数组是 [20,50], 它的最小值是20
40+
大小为3的子数组为[10,20,50], [20,50,10]
41+
有最大的最小值的子数组是 [10,20,50], 它的最小值是10
42+
大小为4的子数组为[10,20,50,10]
43+
有最大的最小值的子数组是 [10,20,50,10], 它的最小值是10</pre>
44+
45+
<p> </p>
46+
47+
<p><strong>提示:</strong></p>
48+
49+
<ul>
50+
<li><code>n == nums.length</code></li>
51+
<li><code>1 <= n <= 10<sup>5</sup></code></li>
52+
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
53+
</ul>
54+
55+
<p> </p>
56+
57+
## 解法
58+
59+
<!-- 这里可写通用的实现逻辑 -->
60+
61+
<!-- tabs:start -->
62+
63+
### **Python3**
64+
65+
<!-- 这里可写当前语言的特殊实现逻辑 -->
66+
67+
```python
68+
69+
```
70+
71+
### **Java**
72+
73+
<!-- 这里可写当前语言的特殊实现逻辑 -->
74+
75+
```java
76+
77+
```
78+
79+
### **...**
80+
81+
```
82+
83+
```
84+
85+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [1950. Maximum of Minimum Values in All Subarrays](https://leetcode.com/problems/maximum-of-minimum-values-in-all-subarrays)
2+
3+
[中文文档](/solution/1900-1999/1950.Maximum%20of%20Minimum%20Values%20in%20All%20Subarrays/README.md)
4+
5+
## Description
6+
7+
<p>You are given an integer array <code>nums</code> of size <code>n</code>. You are asked to solve <code>n</code> queries for each integer <code>i</code> in the range <code>0 &lt;= i &lt; n</code>.</p>
8+
9+
<p>To solve the <code>i<sup>th</sup></code> query:</p>
10+
11+
<ol>
12+
<li>Find the <strong>minimum value</strong> in each possible subarray of size <code>i + 1</code> of the array <code>nums</code>.</li>
13+
<li>Find the <strong>maximum</strong> of those minimum values. This maximum is the <strong>answer</strong> to the query.</li>
14+
</ol>
15+
16+
<p>Return <em>a <strong>0-indexed</strong> integer array</em> <code>ans</code> <em>of size </em><code>n</code> <em>such that </em><code>ans[i]</code> <em>is the answer to the </em><code>i<sup>th</sup></code> <em>query</em>.</p>
17+
18+
<p>A <strong>subarray</strong> is a contiguous sequence of elements in an array.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> nums = [0,1,2,4]
25+
<strong>Output:</strong> [4,2,1,0]
26+
<strong>Explanation:</strong>
27+
i=0:
28+
- The subarrays of size 1 are [0], [1], [2], [4]. The minimum values are 0, 1, 2, 4.
29+
- The maximum of the minimum values is 4.
30+
i=1:
31+
- The subarrays of size 2 are [0,1], [1,2], [2,4]. The minimum values are 0, 1, 2.
32+
- The maximum of the minimum values is 2.
33+
i=2:
34+
- The subarrays of size 3 are [0,1,2], [1,2,4]. The minimum values are 0, 1.
35+
- The maximum of the minimum values is 1.
36+
i=3:
37+
- There is one subarray of size 4, which is [0,1,2,4]. The minimum value is 0.
38+
- There is only one value, so the maximum is 0.
39+
</pre>
40+
41+
<p><strong>Example 2:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong> nums = [10,20,50,10]
45+
<strong>Output:</strong> [50,20,10,10]
46+
<strong>Explanation:</strong>
47+
i=0:
48+
- The subarrays of size 1 are [10], [20], [50], [10]. The minimum values are 10, 20, 50, 10.
49+
- The maximum of the minimum values is 50.
50+
i=1:
51+
- The subarrays of size 2 are [10,20], [20,50], [50,10]. The minimum values are 10, 20, 10.
52+
- The maximum of the minimum values is 20.
53+
i=2:
54+
- The subarrays of size 3 are [10,20,50], [20,50,10]. The minimum values are 10, 10.
55+
- The maximum of the minimum values is 10.
56+
i=3:
57+
- There is one subarray of size 4, which is [10,20,50,10]. The minimum value is 10.
58+
- There is only one value, so the maximum is 10.
59+
</pre>
60+
61+
<p>&nbsp;</p>
62+
<p><strong>Constraints:</strong></p>
63+
64+
<ul>
65+
<li><code>n == nums.length</code></li>
66+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
67+
<li><code>0 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
68+
</ul>
69+
70+
## Solutions
71+
72+
<!-- tabs:start -->
73+
74+
### **Python3**
75+
76+
```python
77+
78+
```
79+
80+
### **Java**
81+
82+
```java
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [1951. All the Pairs With the Maximum Number of Common Followers](https://leetcode-cn.com/problems/all-the-pairs-with-the-maximum-number-of-common-followers)
2+
3+
[English Version](/solution/1900-1999/1951.All%20the%20Pairs%20With%20the%20Maximum%20Number%20of%20Common%20Followers/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Relations</code></p>
10+
11+
<pre>
12+
+-------------+------+
13+
| Column Name | Type |
14+
+-------------+------+
15+
| user_id | int |
16+
| follower_id | int |
17+
+-------------+------+
18+
(user_id, follower_id) is the primary key for this table.
19+
Each row of this table indicates that the user with ID follower_id is following the user with ID user_id.
20+
</pre>
21+
22+
<p>&nbsp;</p>
23+
24+
<p>Write an SQL query to find all the pairs of users with the maximum number of common followers. In other words, if the maximum number of common followers between any two users is <code>maxCommon</code>, then you have to return any pair of users that have <code>maxCommon</code> common followers.</p>
25+
26+
<p>The result table should contain the pairs <code>user1_id</code> and <code>user2_id</code> where <code>user1_id &lt; user2_id</code>.</p>
27+
28+
<p>Return the result table in <strong>any order</strong>.</p>
29+
30+
<p>The query result format is in the following example:</p>
31+
32+
<p>&nbsp;</p>
33+
34+
<pre>
35+
Relations table:
36+
+---------+-------------+
37+
| user_id | follower_id |
38+
+---------+-------------+
39+
| 1 | 3 |
40+
| 2 | 3 |
41+
| 7 | 3 |
42+
| 1 | 4 |
43+
| 2 | 4 |
44+
| 7 | 4 |
45+
| 1 | 5 |
46+
| 2 | 6 |
47+
| 7 | 5 |
48+
+---------+-------------+
49+
50+
Result table:
51+
+----------+----------+
52+
| user1_id | user2_id |
53+
+----------+----------+
54+
| 1 | 7 |
55+
+----------+----------+
56+
57+
Users 1 and 2 have 2 common followers (3 and 4).
58+
Users 1 and 7 have 3 common followers (3, 4, and 5).
59+
Users 2 and 7 have 2 common followers (3 and 4).
60+
Since the maximum number of common followers between any two users is 3, we return any pair of friends with 3 common followers which is only the pair (1, 7) here. We return the pair as [1, 7] not as [7, 1].
61+
Note that we do not have any information about the users that follow users 3, 4, and 5, so we consider them with 0 followers.
62+
</pre>
63+
64+
## 解法
65+
66+
<!-- 这里可写通用的实现逻辑 -->
67+
68+
<!-- tabs:start -->
69+
70+
### **SQL**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```sql
75+
76+
```
77+
78+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# [1951. All the Pairs With the Maximum Number of Common Followers](https://leetcode.com/problems/all-the-pairs-with-the-maximum-number-of-common-followers)
2+
3+
[中文文档](/solution/1900-1999/1951.All%20the%20Pairs%20With%20the%20Maximum%20Number%20of%20Common%20Followers/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Relations</code></p>
8+
9+
<pre>
10+
+-------------+------+
11+
| Column Name | Type |
12+
+-------------+------+
13+
| user_id | int |
14+
| follower_id | int |
15+
+-------------+------+
16+
(user_id, follower_id) is the primary key for this table.
17+
Each row of this table indicates that the user with ID follower_id is following the user with ID user_id.
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
22+
<p>Write an SQL query to find all the pairs of users with the maximum number of common followers. In other words, if the maximum number of common followers between any two users is <code>maxCommon</code>, then you have to return any pair of users that have <code>maxCommon</code> common followers.</p>
23+
24+
<p>The result table should contain the pairs <code>user1_id</code> and <code>user2_id</code> where <code>user1_id &lt; user2_id</code>.</p>
25+
26+
<p>Return the result table in <strong>any order</strong>.</p>
27+
28+
<p>The query result format is in the following example:</p>
29+
30+
<p>&nbsp;</p>
31+
32+
<pre>
33+
Relations table:
34+
+---------+-------------+
35+
| user_id | follower_id |
36+
+---------+-------------+
37+
| 1 | 3 |
38+
| 2 | 3 |
39+
| 7 | 3 |
40+
| 1 | 4 |
41+
| 2 | 4 |
42+
| 7 | 4 |
43+
| 1 | 5 |
44+
| 2 | 6 |
45+
| 7 | 5 |
46+
+---------+-------------+
47+
48+
Result table:
49+
+----------+----------+
50+
| user1_id | user2_id |
51+
+----------+----------+
52+
| 1 | 7 |
53+
+----------+----------+
54+
55+
Users 1 and 2 have 2 common followers (3 and 4).
56+
Users 1 and 7 have 3 common followers (3, 4, and 5).
57+
Users 2 and 7 have 2 common followers (3 and 4).
58+
Since the maximum number of common followers between any two users is 3, we return any pair of friends with 3 common followers which is only the pair (1, 7) here. We return the pair as [1, 7] not as [7, 1].
59+
Note that we do not have any information about the users that follow users 3, 4, and 5, so we consider them with 0 followers.
60+
</pre>
61+
62+
## Solutions
63+
64+
<!-- tabs:start -->
65+
66+
### **SQL**
67+
68+
```sql
69+
70+
```
71+
72+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# [1952. 三除数](https://leetcode-cn.com/problems/three-divisors)
2+
3+
[English Version](/solution/1900-1999/1952.Three%20Divisors/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个整数 <code>n</code> 。如果 <code>n</code> <strong>恰好有三个正除数</strong> ,返回 <code>true</code><em> </em>;否则,返回<em> </em><code>false</code> 。</p>
10+
11+
<p>如果存在整数 <code>k</code> ,满足 <code>n = k * m</code> ,那么整数 <code>m</code> 就是 <code>n</code> 的一个 <strong>除数</strong> 。</p>
12+
13+
<p>&nbsp;</p>
14+
15+
<p><strong>示例 1:</strong></p>
16+
17+
<pre><strong>输入:</strong>n = 2
18+
<strong>输出:</strong>false
19+
<strong>解释:</strong>2 只有两个除数:1 和 2 。</pre>
20+
21+
<p><strong>示例 2:</strong></p>
22+
23+
<pre><strong>输入:</strong>n = 4
24+
<strong>输出:</strong>true
25+
<strong>解释:</strong>4 有三个除数:1、2 和 4 。
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
30+
<p><strong>提示:</strong></p>
31+
32+
<ul>
33+
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
34+
</ul>
35+
36+
## 解法
37+
38+
<!-- 这里可写通用的实现逻辑 -->
39+
40+
<!-- tabs:start -->
41+
42+
### **Python3**
43+
44+
<!-- 这里可写当前语言的特殊实现逻辑 -->
45+
46+
```python
47+
48+
```
49+
50+
### **Java**
51+
52+
<!-- 这里可写当前语言的特殊实现逻辑 -->
53+
54+
```java
55+
56+
```
57+
58+
### **...**
59+
60+
```
61+
62+
```
63+
64+
<!-- tabs:end -->

0 commit comments

Comments
 (0)