Skip to content

Commit 84274cc

Browse files
authored
feat: add solutions to lc problem: No.3172 (#3000)
No.3172.Second Day Verification
1 parent 246e3b4 commit 84274cc

File tree

9 files changed

+281
-3
lines changed

9 files changed

+281
-3
lines changed

Diff for: solution/0100-0199/0152.Maximum Product Subarray/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ tags:
2323

2424
<p>&nbsp;</p>
2525

26-
<p><strong>示例 1:</strong></p>
26+
<p><strong class="example">示例 1:</strong></p>
2727

2828
<pre>
2929
<strong>输入:</strong> nums = [2,3,-2,4]
3030
<strong>输出:</strong> <code>6</code>
3131
<strong>解释:</strong>&nbsp;子数组 [2,3] 有最大乘积 6。
3232
</pre>
3333

34-
<p><strong>示例 2:</strong></p>
34+
<p><strong class="example">示例 2:</strong></p>
3535

3636
<pre>
3737
<strong>输入:</strong> nums = [-2,0,-1]
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3172.Second%20Day%20Verification/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3172. 第二天验证 🔒](https://leetcode.cn/problems/second-day-verification)
10+
11+
[English Version](/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>表:<code>emails</code></p>
18+
19+
<pre>
20+
+-------------+----------+
21+
| Column Name | Type |
22+
+-------------+----------+
23+
| email_id | int |
24+
| user_id | int |
25+
| signup_date | datetime |
26+
+-------------+----------+
27+
(email_id, user_id) 是这张表的主键(有不同值的列的组合)。
28+
这张表的每一行包含 email ID,user ID 和注册日期。
29+
</pre>
30+
31+
<p>表:<code>texts</code></p>
32+
33+
<pre>
34+
+---------------+----------+
35+
| Column Name | Type |
36+
+---------------+----------+
37+
| text_id | int |
38+
| email_id | int |
39+
| signup_action | enum |
40+
| action_date | datetime |
41+
+---------------+----------+
42+
(text_id, email_id) 是这张表的主键(有不同值的列的组合)。
43+
signup_action 是 ('Verified', 'Not Verified') 的枚举类型。
44+
这张表的每一行包含 text ID,email ID,注册操作和操作日期。
45+
</pre>
46+
47+
<p>编写一个解决方案来找到&nbsp;<strong>第二天验证注册</strong>&nbsp;的用户 ID。</p>
48+
49+
<p>返回结果表以&nbsp;<code>user_id</code> <strong>升序&nbsp;</strong>排序。</p>
50+
51+
<p>结果格式如下所示。</p>
52+
53+
<p>&nbsp;</p>
54+
55+
<p><strong class="example">示例:</strong></p>
56+
57+
<div class="example-block">
58+
<p><b>输入:</b></p>
59+
60+
<p>emails 表:</p>
61+
62+
<pre class="example-io">
63+
+----------+---------+---------------------+
64+
| email_id | user_id | signup_date |
65+
+----------+---------+---------------------+
66+
| 125 | 7771 | 2022-06-14 09:30:00|
67+
| 433 | 1052 | 2022-07-09 08:15:00|
68+
| 234 | 7005 | 2022-08-20 10:00:00|
69+
+----------+---------+---------------------+
70+
</pre>
71+
72+
<p>texts 表:</p>
73+
74+
<pre class="example-io">
75+
+---------+----------+--------------+---------------------+
76+
| text_id | email_id | signup_action| action_date |
77+
+---------+----------+--------------+---------------------+
78+
| 1 | 125 | Verified | 2022-06-15 08:30:00|
79+
| 2 | 433 | Not Verified | 2022-07-10 10:45:00|
80+
| 4 | 234 | Verified | 2022-08-21 09:30:00|
81+
+---------+----------+--------------+---------------------+
82+
</pre>
83+
84+
<p><strong>输出:</strong></p>
85+
86+
<pre class="example-io">
87+
+---------+
88+
| user_id |
89+
+---------+
90+
| 7005 |
91+
| 7771 |
92+
+---------+
93+
</pre>
94+
95+
<p><strong>解释:</strong></p>
96+
97+
<ul>
98+
<li>email_id 为 7005 的用户在 2022-08-20 10:00:00 注册并且在第二天验证。</li>
99+
<li>email_id 为 7771 的用户在 2022-06-14 09:30:00 注册并且在第二天验证。</li>
100+
</ul>
101+
</div>
102+
103+
<!-- description:end -->
104+
105+
## 解法
106+
107+
<!-- solution:start -->
108+
109+
### 方法一:双表关联
110+
111+
我们可以通过内连接两个表,然后根据 `DATEDIFF` 函数计算出注册日期和操作日期的差值是否等于 1,以及注册操作是否为 `Verified`,来筛选出满足条件的用户 ID。
112+
113+
<!-- tabs:start -->
114+
115+
#### MySQL
116+
117+
```sql
118+
# Write your MySQL query statement below
119+
SELECT user_id
120+
FROM
121+
Emails AS e
122+
JOIN texts AS t
123+
ON e.email_id = t.email_id
124+
AND DATEDIFF(action_date, signup_date) = 1
125+
AND signup_action = 'Verified'
126+
ORDER BY 1;
127+
```
128+
129+
<!-- tabs:end -->
130+
131+
<!-- solution:end -->
132+
133+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3172. Second Day Verification 🔒](https://leetcode.com/problems/second-day-verification)
10+
11+
[中文文档](/solution/3100-3199/3172.Second%20Day%20Verification/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>Table: <code>emails</code></p>
18+
19+
<pre>
20+
+-------------+----------+
21+
| Column Name | Type |
22+
+-------------+----------+
23+
| email_id | int |
24+
| user_id | int |
25+
| signup_date | datetime |
26+
+-------------+----------+
27+
(email_id, user_id) is the primary key (combination of columns with unique values) for this table.
28+
Each row of this table contains the email ID, user ID, and signup date.
29+
</pre>
30+
31+
<p>Table: <code>texts</code></p>
32+
33+
<pre>
34+
+---------------+----------+
35+
| Column Name | Type |
36+
+---------------+----------+
37+
| text_id | int |
38+
| email_id | int |
39+
| signup_action | enum |
40+
| action_date | datetime |
41+
+---------------+----------+
42+
(text_id, email_id) is the primary key (combination of columns with unique values) for this table.
43+
signup_action is an enum type of (&#39;Verified&#39;, &#39;Not Verified&#39;).
44+
Each row of this table contains the text ID, email ID, signup action, and action date.
45+
</pre>
46+
47+
<p>Write a Solution to find the user IDs of those who <strong>verified</strong> their <strong>sign-up</strong> on the <strong>second day</strong>.</p>
48+
49+
<p>Return <em>the result table ordered by</em> <code>user_id</code> <em>in <strong>ascending</strong> order</em>.</p>
50+
51+
<p>The result format is in the following example.</p>
52+
53+
<p>&nbsp;</p>
54+
<p><strong class="example">Example:</strong></p>
55+
56+
<div class="example-block">
57+
<p><strong>Input:</strong></p>
58+
59+
<p>emails table:</p>
60+
61+
<pre class="example-io">
62+
+----------+---------+---------------------+
63+
| email_id | user_id | signup_date |
64+
+----------+---------+---------------------+
65+
| 125 | 7771 | 2022-06-14 09:30:00|
66+
| 433 | 1052 | 2022-07-09 08:15:00|
67+
| 234 | 7005 | 2022-08-20 10:00:00|
68+
+----------+---------+---------------------+
69+
</pre>
70+
71+
<p>texts table:</p>
72+
73+
<pre class="example-io">
74+
+---------+----------+--------------+---------------------+
75+
| text_id | email_id | signup_action| action_date |
76+
+---------+----------+--------------+---------------------+
77+
| 1 | 125 | Verified | 2022-06-15 08:30:00|
78+
| 2 | 433 | Not Verified | 2022-07-10 10:45:00|
79+
| 4 | 234 | Verified | 2022-08-21 09:30:00|
80+
+---------+----------+--------------+---------------------+
81+
</pre>
82+
83+
<p><strong>Output:</strong></p>
84+
85+
<pre class="example-io">
86+
+---------+
87+
| user_id |
88+
+---------+
89+
| 7005 |
90+
| 7771 |
91+
+---------+
92+
</pre>
93+
94+
<p><strong>Explanation:</strong></p>
95+
96+
<ul>
97+
<li>User with email_id 7005 signed up on 2022-08-20 10:00:00 and&nbsp;verified on second day of the signup.</li>
98+
<li>User with email_id 7771 signed up on 2022-06-14 09:30:00 and&nbsp;verified on second day of the signup.</li>
99+
</ul>
100+
</div>
101+
102+
<!-- description:end -->
103+
104+
## Solutions
105+
106+
<!-- solution:start -->
107+
108+
### Solution 1: Joining Two Tables
109+
110+
We can join the two tables and then use the `DATEDIFF` function to calculate whether the difference between the registration date and the operation date is equal to 1, and whether the registration operation is `Verified`, to filter out the user IDs that meet the conditions.
111+
112+
<!-- tabs:start -->
113+
114+
#### MySQL
115+
116+
```sql
117+
# Write your MySQL query statement below
118+
SELECT user_id
119+
FROM
120+
Emails AS e
121+
JOIN texts AS t
122+
ON e.email_id = t.email_id
123+
AND DATEDIFF(action_date, signup_date) = 1
124+
AND signup_action = 'Verified'
125+
ORDER BY 1;
126+
```
127+
128+
<!-- tabs:end -->
129+
130+
<!-- solution:end -->
131+
132+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write your MySQL query statement below
2+
SELECT user_id
3+
FROM
4+
Emails AS e
5+
JOIN texts AS t
6+
ON e.email_id = t.email_id
7+
AND DATEDIFF(action_date, signup_date) = 1
8+
AND signup_action = 'Verified'
9+
ORDER BY 1;

Diff for: solution/DATABASE_README.md

+1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
| 3150 | [无效的推文 II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | `数据库` | 简单 | 🔒 |
282282
| 3156 | [员工任务持续时间和并发任务](/solution/3100-3199/3156.Employee%20Task%20Duration%20and%20Concurrent%20Tasks/README.md) | `数据库` | 困难 | 🔒 |
283283
| 3166 | [计算停车费与时长](/solution/3100-3199/3166.Calculate%20Parking%20Fees%20and%20Duration/README.md) | `数据库` | 中等 | 🔒 |
284+
| 3172 | [第二天验证](/solution/3100-3199/3172.Second%20Day%20Verification/README.md) | | 简单 | 🔒 |
284285

285286
## 版权
286287

Diff for: solution/DATABASE_README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
279279
| 3150 | [Invalid Tweets II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README_EN.md) | `Database` | Easy | 🔒 |
280280
| 3156 | [Employee Task Duration and Concurrent Tasks](/solution/3100-3199/3156.Employee%20Task%20Duration%20and%20Concurrent%20Tasks/README_EN.md) | `Database` | Hard | 🔒 |
281281
| 3166 | [Calculate Parking Fees and Duration](/solution/3100-3199/3166.Calculate%20Parking%20Fees%20and%20Duration/README_EN.md) | `Database` | Medium | 🔒 |
282+
| 3172 | [Second Day Verification](/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md) | | Easy | 🔒 |
282283

283284
## Copyright
284285

Diff for: solution/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,7 @@
31823182
| 3169 | [无需开会的工作日](/solution/3100-3199/3169.Count%20Days%20Without%20Meetings/README.md) | | 中等 | 第 400 场周赛 |
31833183
| 3170 | [删除星号以后字典序最小的字符串](/solution/3100-3199/3170.Lexicographically%20Minimum%20String%20After%20Removing%20Stars/README.md) | | 中等 | 第 400 场周赛 |
31843184
| 3171 | [找到按位与最接近 K 的子数组](/solution/3100-3199/3171.Find%20Subarray%20With%20Bitwise%20AND%20Closest%20to%20K/README.md) | | 困难 | 第 400 场周赛 |
3185+
| 3172 | [第二天验证](/solution/3100-3199/3172.Second%20Day%20Verification/README.md) | | 简单 | 🔒 |
31853186

31863187
## 版权
31873188

Diff for: solution/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -3180,6 +3180,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
31803180
| 3169 | [Count Days Without Meetings](/solution/3100-3199/3169.Count%20Days%20Without%20Meetings/README_EN.md) | | Medium | Weekly Contest 400 |
31813181
| 3170 | [Lexicographically Minimum String After Removing Stars](/solution/3100-3199/3170.Lexicographically%20Minimum%20String%20After%20Removing%20Stars/README_EN.md) | | Medium | Weekly Contest 400 |
31823182
| 3171 | [Find Subarray With Bitwise AND Closest to K](/solution/3100-3199/3171.Find%20Subarray%20With%20Bitwise%20AND%20Closest%20to%20K/README_EN.md) | | Hard | Weekly Contest 400 |
3183+
| 3172 | [Second Day Verification](/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md) | | Easy | 🔒 |
31833184

31843185
## Copyright
31853186

Diff for: solution/contest.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)