Skip to content

Commit 363092a

Browse files
committed
feat: add new lc problems
1 parent 5f8273e commit 363092a

File tree

27 files changed

+1556
-421
lines changed

27 files changed

+1556
-421
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [1990. Count the Number of Experiments](https://leetcode-cn.com/problems/count-the-number-of-experiments)
2+
3+
[English Version](/solution/1900-1999/1990.Count%20the%20Number%20of%20Experiments/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Experiments</code></p>
10+
11+
<pre>
12+
+-----------------+------+
13+
| Column Name | Type |
14+
+-----------------+------+
15+
| experiment_id | int |
16+
| platform | enum |
17+
| experiment_name | enum |
18+
+-----------------+------+
19+
experiment_id is the primary key for this table.
20+
platform is an enum with one of the values (&#39;Android&#39;, &#39;IOS&#39;, &#39;Web&#39;).
21+
experiment_name is an enum with one of the values (&#39;Reading&#39;, &#39;Sports&#39;, &#39;Programming&#39;).
22+
This table contains information about the ID of an experiment done with a random person, the platform used to do the experiment, and the name of the experiment.
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
27+
<p>Write an SQL query to report the <strong>number of experiments</strong> done on each of the three platforms for each of the three given experiments. Notice that all the pairs of (platform, experiment) should be included in the output <strong>including</strong> the pairs with <strong>zero experiments</strong>.</p>
28+
29+
<p>Return the result table in <strong>any order</strong>.</p>
30+
31+
<p>The query result format is in the following example.</p>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Example 1:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong>
38+
Experiments table:
39+
+---------------+----------+-----------------+
40+
| experiment_id | platform | experiment_name |
41+
+---------------+----------+-----------------+
42+
| 4 | IOS | Programming |
43+
| 13 | IOS | Sports |
44+
| 14 | Android | Reading |
45+
| 8 | Web | Reading |
46+
| 12 | Web | Reading |
47+
| 18 | Web | Programming |
48+
+---------------+----------+-----------------+
49+
<strong>Output:</strong>
50+
+----------+-----------------+-----------------+
51+
| platform | experiment_name | num_experiments |
52+
+----------+-----------------+-----------------+
53+
| Android | Reading | 1 |
54+
| Android | Sports | 0 |
55+
| Android | Programming | 0 |
56+
| IOS | Reading | 0 |
57+
| IOS | Sports | 1 |
58+
| IOS | Programming | 1 |
59+
| Web | Reading | 2 |
60+
| Web | Sports | 0 |
61+
| Web | Programming | 1 |
62+
+----------+-----------------+-----------------+
63+
<strong>Explanation:</strong>
64+
On the platform &quot;Android&quot;, we had only one &quot;Reading&quot; experiment.
65+
On the platform &quot;IOS&quot;, we had one &quot;Sports&quot; experiment and one &quot;Programming&quot; experiment.
66+
On the platform &quot;Web&quot;, we had two &quot;Reading&quot; experiments and one &quot;Programming&quot; experiment.
67+
</pre>
68+
69+
70+
## 解法
71+
72+
<!-- 这里可写通用的实现逻辑 -->
73+
74+
<!-- tabs:start -->
75+
76+
### **SQL**
77+
78+
<!-- 这里可写当前语言的特殊实现逻辑 -->
79+
80+
```sql
81+
82+
```
83+
84+
<!-- tabs:end -->
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [1990. Count the Number of Experiments](https://leetcode.com/problems/count-the-number-of-experiments)
2+
3+
[中文文档](/solution/1900-1999/1990.Count%20the%20Number%20of%20Experiments/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Experiments</code></p>
8+
9+
<pre>
10+
+-----------------+------+
11+
| Column Name | Type |
12+
+-----------------+------+
13+
| experiment_id | int |
14+
| platform | enum |
15+
| experiment_name | enum |
16+
+-----------------+------+
17+
experiment_id is the primary key for this table.
18+
platform is an enum with one of the values (&#39;Android&#39;, &#39;IOS&#39;, &#39;Web&#39;).
19+
experiment_name is an enum with one of the values (&#39;Reading&#39;, &#39;Sports&#39;, &#39;Programming&#39;).
20+
This table contains information about the ID of an experiment done with a random person, the platform used to do the experiment, and the name of the experiment.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Write an SQL query to report the <strong>number of experiments</strong> done on each of the three platforms for each of the three given experiments. Notice that all the pairs of (platform, experiment) should be included in the output <strong>including</strong> the pairs with <strong>zero experiments</strong>.</p>
26+
27+
<p>Return the result table in <strong>any order</strong>.</p>
28+
29+
<p>The query result format is in the following example.</p>
30+
31+
<p>&nbsp;</p>
32+
<p><strong>Example 1:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong>
36+
Experiments table:
37+
+---------------+----------+-----------------+
38+
| experiment_id | platform | experiment_name |
39+
+---------------+----------+-----------------+
40+
| 4 | IOS | Programming |
41+
| 13 | IOS | Sports |
42+
| 14 | Android | Reading |
43+
| 8 | Web | Reading |
44+
| 12 | Web | Reading |
45+
| 18 | Web | Programming |
46+
+---------------+----------+-----------------+
47+
<strong>Output:</strong>
48+
+----------+-----------------+-----------------+
49+
| platform | experiment_name | num_experiments |
50+
+----------+-----------------+-----------------+
51+
| Android | Reading | 1 |
52+
| Android | Sports | 0 |
53+
| Android | Programming | 0 |
54+
| IOS | Reading | 0 |
55+
| IOS | Sports | 1 |
56+
| IOS | Programming | 1 |
57+
| Web | Reading | 2 |
58+
| Web | Sports | 0 |
59+
| Web | Programming | 1 |
60+
+----------+-----------------+-----------------+
61+
<strong>Explanation:</strong>
62+
On the platform &quot;Android&quot;, we had only one &quot;Reading&quot; experiment.
63+
On the platform &quot;IOS&quot;, we had one &quot;Sports&quot; experiment and one &quot;Programming&quot; experiment.
64+
On the platform &quot;Web&quot;, we had two &quot;Reading&quot; experiments and one &quot;Programming&quot; experiment.
65+
</pre>
66+
67+
68+
## Solutions
69+
70+
<!-- tabs:start -->
71+
72+
### **SQL**
73+
74+
```sql
75+
76+
```
77+
78+
<!-- tabs:end -->
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [1991. 找到数组的中间位置](https://leetcode-cn.com/problems/find-the-middle-index-in-array)
2+
3+
[English Version](/solution/1900-1999/1991.Find%20the%20Middle%20Index%20in%20Array/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code>&nbsp;,请你找到 <strong>最左边</strong>&nbsp;的中间位置&nbsp;<code>middleIndex</code>&nbsp;(也就是所有可能中间位置下标最小的一个)。</p>
10+
11+
<p>中间位置&nbsp;<code>middleIndex</code>&nbsp;是满足&nbsp;<code>nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1]</code>&nbsp;的数组下标。</p>
12+
13+
<p>如果&nbsp;<code>middleIndex == 0</code>&nbsp;,左边部分的和定义为 <code>0</code>&nbsp;。类似的,如果&nbsp;<code>middleIndex == nums.length - 1</code>&nbsp;,右边部分的和定义为&nbsp;<code>0</code>&nbsp;。</p>
14+
15+
<p>请你返回满足上述条件 <strong>最左边</strong>&nbsp;的<em>&nbsp;</em><code>middleIndex</code>&nbsp;,如果不存在这样的中间位置,请你返回&nbsp;<code>-1</code>&nbsp;。</p>
16+
17+
<p>&nbsp;</p>
18+
19+
<p><strong>示例 1:</strong></p>
20+
21+
<pre><b>输入:</b>nums = [2,3,-1,<em><strong>8</strong></em>,4]
22+
<b>输出:</b>3
23+
<strong>解释:</strong>
24+
下标 3 之前的数字和为:2 + 3 + -1 = 4
25+
下标 3 之后的数字和为:4 = 4
26+
</pre>
27+
28+
<p><strong>示例 2:</strong></p>
29+
30+
<pre><b>输入:</b>nums = [1,-1,<em><strong>4</strong></em>]
31+
<b>输出:</b>2
32+
<strong>解释:</strong>
33+
下标 2 之前的数字和为:1 + -1 = 0
34+
下标 2 之后的数字和为:0
35+
</pre>
36+
37+
<p><strong>示例 3:</strong></p>
38+
39+
<pre><b>输入:</b>nums = [2,5]
40+
<b>输出:</b>-1
41+
<b>解释:</b>
42+
不存在符合要求的 middleIndex 。
43+
</pre>
44+
45+
<p><strong>示例 4:</strong></p>
46+
47+
<pre><b>输入:</b>nums = [<em><strong>1</strong></em>]
48+
<b>输出:</b>0
49+
<strong>解释:</strong>
50+
下标 0 之前的数字和为:0
51+
下标 0 之后的数字和为:0
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
56+
<p><strong>提示:</strong></p>
57+
58+
<ul>
59+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
60+
<li><code>-1000 &lt;= nums[i] &lt;= 1000</code></li>
61+
</ul>
62+
63+
64+
## 解法
65+
66+
<!-- 这里可写通用的实现逻辑 -->
67+
68+
<!-- tabs:start -->
69+
70+
### **Python3**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```python
75+
76+
```
77+
78+
### **Java**
79+
80+
<!-- 这里可写当前语言的特殊实现逻辑 -->
81+
82+
```java
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [1991. Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array)
2+
3+
[中文文档](/solution/1900-1999/1991.Find%20the%20Middle%20Index%20in%20Array/README.md)
4+
5+
## Description
6+
7+
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find the <strong>leftmost</strong> <code>middleIndex</code> (i.e., the smallest amongst all the possible ones).</p>
8+
9+
<p>A <code>middleIndex</code> is an index where <code>nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1]</code>.</p>
10+
11+
<p>If <code>middleIndex == 0</code>, the left side sum is considered to be <code>0</code>. Similarly, if <code>middleIndex == nums.length - 1</code>, the right side sum is considered to be <code>0</code>.</p>
12+
13+
<p>Return <em>the <strong>leftmost</strong> </em><code>middleIndex</code><em> that satisfies the condition, or </em><code>-1</code><em> if there is no such index</em>.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> nums = [2,3,-1,<u>8</u>,4]
20+
<strong>Output:</strong> 3
21+
<strong>Explanation:</strong>
22+
The sum of the numbers before index 3 is: 2 + 3 + -1 = 4
23+
The sum of the numbers after index 3 is: 4 = 4
24+
</pre>
25+
26+
<p><strong>Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> nums = [1,-1,<u>4</u>]
30+
<strong>Output:</strong> 2
31+
<strong>Explanation:</strong>
32+
The sum of the numbers before index 2 is: 1 + -1 = 0
33+
The sum of the numbers after index 2 is: 0
34+
</pre>
35+
36+
<p><strong>Example 3:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> nums = [2,5]
40+
<strong>Output:</strong> -1
41+
<strong>Explanation:</strong>
42+
There is no valid middleIndex.
43+
</pre>
44+
45+
<p><strong>Example 4:</strong></p>
46+
47+
<pre>
48+
<strong>Input:</strong> nums = [<u>1</u>]
49+
<strong>Output:</strong> 0
50+
<strong>Explantion:</strong>
51+
The sum of the numbers before index 0 is: 0
52+
The sum of the numbers after index 0 is: 0
53+
</pre>
54+
55+
<p>&nbsp;</p>
56+
<p><strong>Constraints:</strong></p>
57+
58+
<ul>
59+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
60+
<li><code>-1000 &lt;= nums[i] &lt;= 1000</code></li>
61+
</ul>
62+
63+
64+
## Solutions
65+
66+
<!-- tabs:start -->
67+
68+
### **Python3**
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
```java
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->

0 commit comments

Comments
 (0)