Skip to content

Commit e635cf5

Browse files
committed
feat: add new lc problems
1 parent ccbcdea commit e635cf5

File tree

8 files changed

+9352
-9060
lines changed

8 files changed

+9352
-9060
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# [2228. Users With Two Purchases Within Seven Days](https://leetcode-cn.com/problems/users-with-two-purchases-within-seven-days)
2+
3+
[English Version](/solution/2200-2299/2228.Users%20With%20Two%20Purchases%20Within%20Seven%20Days/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Purchases</code></p>
10+
11+
<pre>
12+
+---------------+------+
13+
| Column Name | Type |
14+
+---------------+------+
15+
| purchase_id | int |
16+
| user_id | int |
17+
| purchase_date | date |
18+
+---------------+------+
19+
purchase_id is the primary key for this table.
20+
This table contains logs of the dates that users purchased from a certain retailer.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Write an SQL query to report the IDs of the users that made any two purchases <strong>at most</strong> <code>7</code> days apart.</p>
26+
27+
<p>Return the result table ordered by <code>user_id</code>.</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+
Purchases table:
37+
+-------------+---------+---------------+
38+
| purchase_id | user_id | purchase_date |
39+
+-------------+---------+---------------+
40+
| 4 | 2 | 2022-03-13 |
41+
| 1 | 5 | 2022-02-11 |
42+
| 3 | 7 | 2022-06-19 |
43+
| 6 | 2 | 2022-03-20 |
44+
| 5 | 7 | 2022-06-19 |
45+
| 2 | 2 | 2022-06-08 |
46+
+-------------+---------+---------------+
47+
<strong>Output:</strong>
48+
+---------+
49+
| user_id |
50+
+---------+
51+
| 2 |
52+
| 7 |
53+
+---------+
54+
<strong>Explanation:</strong>
55+
User 2 had two purchases on 2022-03-13 and 2022-03-20. Since the second purchase is within 7 days of the first purchase, we add their ID.
56+
User 5 had only 1 purchase.
57+
User 7 had two purchases on the same day so we add their ID.
58+
</pre>
59+
60+
## 解法
61+
62+
<!-- 这里可写通用的实现逻辑 -->
63+
64+
<!-- tabs:start -->
65+
66+
### **SQL**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```sql
71+
72+
```
73+
74+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# [2228. Users With Two Purchases Within Seven Days](https://leetcode.com/problems/users-with-two-purchases-within-seven-days)
2+
3+
[中文文档](/solution/2200-2299/2228.Users%20With%20Two%20Purchases%20Within%20Seven%20Days/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Purchases</code></p>
8+
9+
<pre>
10+
+---------------+------+
11+
| Column Name | Type |
12+
+---------------+------+
13+
| purchase_id | int |
14+
| user_id | int |
15+
| purchase_date | date |
16+
+---------------+------+
17+
purchase_id is the primary key for this table.
18+
This table contains logs of the dates that users purchased from a certain retailer.
19+
</pre>
20+
21+
<p>&nbsp;</p>
22+
23+
<p>Write an SQL query to report the IDs of the users that made any two purchases <strong>at most</strong> <code>7</code> days apart.</p>
24+
25+
<p>Return the result table ordered by <code>user_id</code>.</p>
26+
27+
<p>The query result format is in the following example.</p>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Example 1:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong>
34+
Purchases table:
35+
+-------------+---------+---------------+
36+
| purchase_id | user_id | purchase_date |
37+
+-------------+---------+---------------+
38+
| 4 | 2 | 2022-03-13 |
39+
| 1 | 5 | 2022-02-11 |
40+
| 3 | 7 | 2022-06-19 |
41+
| 6 | 2 | 2022-03-20 |
42+
| 5 | 7 | 2022-06-19 |
43+
| 2 | 2 | 2022-06-08 |
44+
+-------------+---------+---------------+
45+
<strong>Output:</strong>
46+
+---------+
47+
| user_id |
48+
+---------+
49+
| 2 |
50+
| 7 |
51+
+---------+
52+
<strong>Explanation:</strong>
53+
User 2 had two purchases on 2022-03-13 and 2022-03-20. Since the second purchase is within 7 days of the first purchase, we add their ID.
54+
User 5 had only 1 purchase.
55+
User 7 had two purchases on the same day so we add their ID.
56+
</pre>
57+
58+
## Solutions
59+
60+
<!-- tabs:start -->
61+
62+
### **SQL**
63+
64+
```sql
65+
66+
```
67+
68+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# [2229. Check if an Array Is Consecutive](https://leetcode-cn.com/problems/check-if-an-array-is-consecutive)
2+
3+
[English Version](/solution/2200-2299/2229.Check%20if%20an%20Array%20Is%20Consecutive/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if </em><code>nums</code><em> is <strong>consecutive</strong>, otherwise return </em><code>false</code><em>.</em></p>
10+
11+
<p>An array is <strong>consecutive </strong>if it contains every number in the range <code>[x, x + n - 1]</code> (<strong>inclusive</strong>), where <code>x</code> is the minimum number in the array and <code>n</code> is the length of the array.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> nums = [1,3,4,2]
18+
<strong>Output:</strong> true
19+
<strong>Explanation:</strong>
20+
The minimum value is 1 and the length of nums is 4.
21+
All of the values in the range [x, x + n - 1] = [1, 1 + 4 - 1] = [1, 4] = (1, 2, 3, 4) occur in nums.
22+
Therefore, nums is consecutive.
23+
</pre>
24+
25+
<p><strong>Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> nums = [1,3]
29+
<strong>Output:</strong> false
30+
<strong>Explanation:</strong>
31+
The minimum value is 1 and the length of nums is 2.
32+
The value 2 in the range [x, x + n - 1] = [1, 1 + 2 - 1], = [1, 2] = (1, 2) does not occur in nums.
33+
Therefore, nums is not consecutive.
34+
</pre>
35+
36+
<p><strong>Example 3:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> nums = [3,5,4]
40+
<strong>Output:</strong> true
41+
<strong>Explanation:</strong>
42+
The minimum value is 3 and the length of nums is 3.
43+
All of the values in the range [x, x + n - 1] = [3, 3 + 3 - 1] = [3, 5] = (3, 4, 5) occur in nums.
44+
Therefore, nums is consecutive.
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
52+
<li><code>0 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
53+
</ul>
54+
55+
## 解法
56+
57+
<!-- 这里可写通用的实现逻辑 -->
58+
59+
<!-- tabs:start -->
60+
61+
### **Python3**
62+
63+
<!-- 这里可写当前语言的特殊实现逻辑 -->
64+
65+
```python
66+
67+
```
68+
69+
### **Java**
70+
71+
<!-- 这里可写当前语言的特殊实现逻辑 -->
72+
73+
```java
74+
75+
```
76+
77+
### **TypeScript**
78+
79+
```ts
80+
81+
```
82+
83+
### **...**
84+
85+
```
86+
87+
```
88+
89+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# [2229. Check if an Array Is Consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive)
2+
3+
[中文文档](/solution/2200-2299/2229.Check%20if%20an%20Array%20Is%20Consecutive/README.md)
4+
5+
## Description
6+
7+
<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if </em><code>nums</code><em> is <strong>consecutive</strong>, otherwise return </em><code>false</code><em>.</em></p>
8+
9+
<p>An array is <strong>consecutive </strong>if it contains every number in the range <code>[x, x + n - 1]</code> (<strong>inclusive</strong>), where <code>x</code> is the minimum number in the array and <code>n</code> is the length of the array.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong>Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> nums = [1,3,4,2]
16+
<strong>Output:</strong> true
17+
<strong>Explanation:</strong>
18+
The minimum value is 1 and the length of nums is 4.
19+
All of the values in the range [x, x + n - 1] = [1, 1 + 4 - 1] = [1, 4] = (1, 2, 3, 4) occur in nums.
20+
Therefore, nums is consecutive.
21+
</pre>
22+
23+
<p><strong>Example 2:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> nums = [1,3]
27+
<strong>Output:</strong> false
28+
<strong>Explanation:</strong>
29+
The minimum value is 1 and the length of nums is 2.
30+
The value 2 in the range [x, x + n - 1] = [1, 1 + 2 - 1], = [1, 2] = (1, 2) does not occur in nums.
31+
Therefore, nums is not consecutive.
32+
</pre>
33+
34+
<p><strong>Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> nums = [3,5,4]
38+
<strong>Output:</strong> true
39+
<strong>Explanation:</strong>
40+
The minimum value is 3 and the length of nums is 3.
41+
All of the values in the range [x, x + n - 1] = [3, 3 + 3 - 1] = [3, 5] = (3, 4, 5) occur in nums.
42+
Therefore, nums is consecutive.
43+
</pre>
44+
45+
<p>&nbsp;</p>
46+
<p><strong>Constraints:</strong></p>
47+
48+
<ul>
49+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
50+
<li><code>0 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
51+
</ul>
52+
53+
## Solutions
54+
55+
<!-- tabs:start -->
56+
57+
### **Python3**
58+
59+
```python
60+
61+
```
62+
63+
### **Java**
64+
65+
```java
66+
67+
```
68+
69+
### **TypeScript**
70+
71+
```ts
72+
73+
```
74+
75+
### **...**
76+
77+
```
78+
79+
```
80+
81+
<!-- tabs:end -->

0 commit comments

Comments
 (0)