Skip to content

feat: add solutions to lc problem: No.3172 #3000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions solution/0100-0199/0152.Maximum Product Subarray/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ tags:

<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<p><strong class="example">示例 1:</strong></p>

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

<p><strong>示例 2:</strong></p>
<p><strong class="example">示例 2:</strong></p>

<pre>
<strong>输入:</strong> nums = [-2,0,-1]
Expand Down
133 changes: 133 additions & 0 deletions solution/3100-3199/3172.Second Day Verification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3172.Second%20Day%20Verification/README.md
---

<!-- problem:start -->

# [3172. 第二天验证 🔒](https://leetcode.cn/problems/second-day-verification)

[English Version](/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md)

## 题目描述

<!-- description:start -->

<p>表:<code>emails</code></p>

<pre>
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| email_id | int |
| user_id | int |
| signup_date | datetime |
+-------------+----------+
(email_id, user_id) 是这张表的主键(有不同值的列的组合)。
这张表的每一行包含 email ID,user ID 和注册日期。
</pre>

<p>表:<code>texts</code></p>

<pre>
+---------------+----------+
| Column Name | Type |
+---------------+----------+
| text_id | int |
| email_id | int |
| signup_action | enum |
| action_date | datetime |
+---------------+----------+
(text_id, email_id) 是这张表的主键(有不同值的列的组合)。
signup_action 是 ('Verified', 'Not Verified') 的枚举类型。
这张表的每一行包含 text ID,email ID,注册操作和操作日期。
</pre>

<p>编写一个解决方案来找到&nbsp;<strong>第二天验证注册</strong>&nbsp;的用户 ID。</p>

<p>返回结果表以&nbsp;<code>user_id</code> <strong>升序&nbsp;</strong>排序。</p>

<p>结果格式如下所示。</p>

<p>&nbsp;</p>

<p><strong class="example">示例:</strong></p>

<div class="example-block">
<p><b>输入:</b></p>

<p>emails 表:</p>

<pre class="example-io">
+----------+---------+---------------------+
| email_id | user_id | signup_date |
+----------+---------+---------------------+
| 125 | 7771 | 2022-06-14 09:30:00|
| 433 | 1052 | 2022-07-09 08:15:00|
| 234 | 7005 | 2022-08-20 10:00:00|
+----------+---------+---------------------+
</pre>

<p>texts 表:</p>

<pre class="example-io">
+---------+----------+--------------+---------------------+
| text_id | email_id | signup_action| action_date |
+---------+----------+--------------+---------------------+
| 1 | 125 | Verified | 2022-06-15 08:30:00|
| 2 | 433 | Not Verified | 2022-07-10 10:45:00|
| 4 | 234 | Verified | 2022-08-21 09:30:00|
+---------+----------+--------------+---------------------+
</pre>

<p><strong>输出:</strong></p>

<pre class="example-io">
+---------+
| user_id |
+---------+
| 7005 |
| 7771 |
+---------+
</pre>

<p><strong>解释:</strong></p>

<ul>
<li>email_id 为 7005 的用户在 2022-08-20 10:00:00 注册并且在第二天验证。</li>
<li>email_id 为 7771 的用户在 2022-06-14 09:30:00 注册并且在第二天验证。</li>
</ul>
</div>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一:双表关联

我们可以通过内连接两个表,然后根据 `DATEDIFF` 函数计算出注册日期和操作日期的差值是否等于 1,以及注册操作是否为 `Verified`,来筛选出满足条件的用户 ID。

<!-- tabs:start -->

#### MySQL

```sql
# Write your MySQL query statement below
SELECT user_id
FROM
Emails AS e
JOIN texts AS t
ON e.email_id = t.email_id
AND DATEDIFF(action_date, signup_date) = 1
AND signup_action = 'Verified'
ORDER BY 1;
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
132 changes: 132 additions & 0 deletions solution/3100-3199/3172.Second Day Verification/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md
---

<!-- problem:start -->

# [3172. Second Day Verification 🔒](https://leetcode.com/problems/second-day-verification)

[中文文档](/solution/3100-3199/3172.Second%20Day%20Verification/README.md)

## Description

<!-- description:start -->

<p>Table: <code>emails</code></p>

<pre>
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| email_id | int |
| user_id | int |
| signup_date | datetime |
+-------------+----------+
(email_id, user_id) is the primary key (combination of columns with unique values) for this table.
Each row of this table contains the email ID, user ID, and signup date.
</pre>

<p>Table: <code>texts</code></p>

<pre>
+---------------+----------+
| Column Name | Type |
+---------------+----------+
| text_id | int |
| email_id | int |
| signup_action | enum |
| action_date | datetime |
+---------------+----------+
(text_id, email_id) is the primary key (combination of columns with unique values) for this table.
signup_action is an enum type of (&#39;Verified&#39;, &#39;Not Verified&#39;).
Each row of this table contains the text ID, email ID, signup action, and action date.
</pre>

<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>

<p>Return <em>the result table ordered by</em> <code>user_id</code> <em>in <strong>ascending</strong> order</em>.</p>

<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example:</strong></p>

<div class="example-block">
<p><strong>Input:</strong></p>

<p>emails table:</p>

<pre class="example-io">
+----------+---------+---------------------+
| email_id | user_id | signup_date |
+----------+---------+---------------------+
| 125 | 7771 | 2022-06-14 09:30:00|
| 433 | 1052 | 2022-07-09 08:15:00|
| 234 | 7005 | 2022-08-20 10:00:00|
+----------+---------+---------------------+
</pre>

<p>texts table:</p>

<pre class="example-io">
+---------+----------+--------------+---------------------+
| text_id | email_id | signup_action| action_date |
+---------+----------+--------------+---------------------+
| 1 | 125 | Verified | 2022-06-15 08:30:00|
| 2 | 433 | Not Verified | 2022-07-10 10:45:00|
| 4 | 234 | Verified | 2022-08-21 09:30:00|
+---------+----------+--------------+---------------------+
</pre>

<p><strong>Output:</strong></p>

<pre class="example-io">
+---------+
| user_id |
+---------+
| 7005 |
| 7771 |
+---------+
</pre>

<p><strong>Explanation:</strong></p>

<ul>
<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>
<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>
</ul>
</div>

<!-- description:end -->

## Solutions

<!-- solution:start -->

### Solution 1: Joining Two Tables

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.

<!-- tabs:start -->

#### MySQL

```sql
# Write your MySQL query statement below
SELECT user_id
FROM
Emails AS e
JOIN texts AS t
ON e.email_id = t.email_id
AND DATEDIFF(action_date, signup_date) = 1
AND signup_action = 'Verified'
ORDER BY 1;
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
9 changes: 9 additions & 0 deletions solution/3100-3199/3172.Second Day Verification/Solution.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Write your MySQL query statement below
SELECT user_id
FROM
Emails AS e
JOIN texts AS t
ON e.email_id = t.email_id
AND DATEDIFF(action_date, signup_date) = 1
AND signup_action = 'Verified'
ORDER BY 1;
1 change: 1 addition & 0 deletions solution/DATABASE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
| 3150 | [无效的推文 II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README.md) | `数据库` | 简单 | 🔒 |
| 3156 | [员工任务持续时间和并发任务](/solution/3100-3199/3156.Employee%20Task%20Duration%20and%20Concurrent%20Tasks/README.md) | `数据库` | 困难 | 🔒 |
| 3166 | [计算停车费与时长](/solution/3100-3199/3166.Calculate%20Parking%20Fees%20and%20Duration/README.md) | `数据库` | 中等 | 🔒 |
| 3172 | [第二天验证](/solution/3100-3199/3172.Second%20Day%20Verification/README.md) | | 简单 | 🔒 |

## 版权

Expand Down
1 change: 1 addition & 0 deletions solution/DATABASE_README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 3150 | [Invalid Tweets II](/solution/3100-3199/3150.Invalid%20Tweets%20II/README_EN.md) | `Database` | Easy | 🔒 |
| 3156 | [Employee Task Duration and Concurrent Tasks](/solution/3100-3199/3156.Employee%20Task%20Duration%20and%20Concurrent%20Tasks/README_EN.md) | `Database` | Hard | 🔒 |
| 3166 | [Calculate Parking Fees and Duration](/solution/3100-3199/3166.Calculate%20Parking%20Fees%20and%20Duration/README_EN.md) | `Database` | Medium | 🔒 |
| 3172 | [Second Day Verification](/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md) | | Easy | 🔒 |

## Copyright

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

## 版权

Expand Down
1 change: 1 addition & 0 deletions solution/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3180,6 +3180,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 3169 | [Count Days Without Meetings](/solution/3100-3199/3169.Count%20Days%20Without%20Meetings/README_EN.md) | | Medium | Weekly Contest 400 |
| 3170 | [Lexicographically Minimum String After Removing Stars](/solution/3100-3199/3170.Lexicographically%20Minimum%20String%20After%20Removing%20Stars/README_EN.md) | | Medium | Weekly Contest 400 |
| 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 |
| 3172 | [Second Day Verification](/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md) | | Easy | 🔒 |

## Copyright

Expand Down
2 changes: 1 addition & 1 deletion solution/contest.json

Large diffs are not rendered by default.