mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 23:11:41 +08:00
update
This commit is contained in:
75
leetcode/problem/average-selling-price.html
Normal file
75
leetcode/problem/average-selling-price.html
Normal file
@@ -0,0 +1,75 @@
|
||||
<p>Table: <code>Prices</code></p>
|
||||
|
||||
<pre>
|
||||
+---------------+---------+
|
||||
| Column Name | Type |
|
||||
+---------------+---------+
|
||||
| product_id | int |
|
||||
| start_date | date |
|
||||
| end_date | date |
|
||||
| price | int |
|
||||
+---------------+---------+
|
||||
(product_id, start_date, end_date) is the primary key (combination of columns with unique values) for this table.
|
||||
Each row of this table indicates the price of the product_id in the period from start_date to end_date.
|
||||
For each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Table: <code>UnitsSold</code></p>
|
||||
|
||||
<pre>
|
||||
+---------------+---------+
|
||||
| Column Name | Type |
|
||||
+---------------+---------+
|
||||
| product_id | int |
|
||||
| purchase_date | date |
|
||||
| units | int |
|
||||
+---------------+---------+
|
||||
This table may contain duplicate rows.
|
||||
Each row of this table indicates the date, units, and product_id of each product sold.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a solution to find the average selling price for each product. <code>average_price</code> should be <strong>rounded to 2 decimal places</strong>.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Prices table:
|
||||
+------------+------------+------------+--------+
|
||||
| product_id | start_date | end_date | price |
|
||||
+------------+------------+------------+--------+
|
||||
| 1 | 2019-02-17 | 2019-02-28 | 5 |
|
||||
| 1 | 2019-03-01 | 2019-03-22 | 20 |
|
||||
| 2 | 2019-02-01 | 2019-02-20 | 15 |
|
||||
| 2 | 2019-02-21 | 2019-03-31 | 30 |
|
||||
+------------+------------+------------+--------+
|
||||
UnitsSold table:
|
||||
+------------+---------------+-------+
|
||||
| product_id | purchase_date | units |
|
||||
+------------+---------------+-------+
|
||||
| 1 | 2019-02-25 | 100 |
|
||||
| 1 | 2019-03-01 | 15 |
|
||||
| 2 | 2019-02-10 | 200 |
|
||||
| 2 | 2019-03-22 | 30 |
|
||||
+------------+---------------+-------+
|
||||
<strong>Output:</strong>
|
||||
+------------+---------------+
|
||||
| product_id | average_price |
|
||||
+------------+---------------+
|
||||
| 1 | 6.96 |
|
||||
| 2 | 16.96 |
|
||||
+------------+---------------+
|
||||
<strong>Explanation:</strong>
|
||||
Average selling price = Total Price of Product / Number of products sold.
|
||||
Average selling price for product 1 = ((100 * 5) + (15 * 20)) / 115 = 6.96
|
||||
Average selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96
|
||||
</pre>
|
68
leetcode/problem/average-time-of-process-per-machine.html
Normal file
68
leetcode/problem/average-time-of-process-per-machine.html
Normal file
@@ -0,0 +1,68 @@
|
||||
<p>Table: <code>Activity</code></p>
|
||||
|
||||
<pre>
|
||||
+----------------+---------+
|
||||
| Column Name | Type |
|
||||
+----------------+---------+
|
||||
| machine_id | int |
|
||||
| process_id | int |
|
||||
| activity_type | enum |
|
||||
| timestamp | float |
|
||||
+----------------+---------+
|
||||
The table shows the user activities for a factory website.
|
||||
(machine_id, process_id, activity_type) is the primary key (combination of columns with unique values) of this table.
|
||||
machine_id is the ID of a machine.
|
||||
process_id is the ID of a process running on the machine with ID machine_id.
|
||||
activity_type is an ENUM (category) of type ('start', 'end').
|
||||
timestamp is a float representing the current time in seconds.
|
||||
'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.
|
||||
The 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>There is a factory website that has several machines each running the <strong>same number of processes</strong>. Write a solution to find the <strong>average time</strong> each machine takes to complete a process.</p>
|
||||
|
||||
<p>The time to complete a process is the <code>'end' timestamp</code> minus the <code>'start' timestamp</code>. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.</p>
|
||||
|
||||
<p>The resulting table should have the <code>machine_id</code> along with the <strong>average time</strong> as <code>processing_time</code>, which should be <strong>rounded to 3 decimal places</strong>.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Activity table:
|
||||
+------------+------------+---------------+-----------+
|
||||
| machine_id | process_id | activity_type | timestamp |
|
||||
+------------+------------+---------------+-----------+
|
||||
| 0 | 0 | start | 0.712 |
|
||||
| 0 | 0 | end | 1.520 |
|
||||
| 0 | 1 | start | 3.140 |
|
||||
| 0 | 1 | end | 4.120 |
|
||||
| 1 | 0 | start | 0.550 |
|
||||
| 1 | 0 | end | 1.550 |
|
||||
| 1 | 1 | start | 0.430 |
|
||||
| 1 | 1 | end | 1.420 |
|
||||
| 2 | 0 | start | 4.100 |
|
||||
| 2 | 0 | end | 4.512 |
|
||||
| 2 | 1 | start | 2.500 |
|
||||
| 2 | 1 | end | 5.000 |
|
||||
+------------+------------+---------------+-----------+
|
||||
<strong>Output:</strong>
|
||||
+------------+-----------------+
|
||||
| machine_id | processing_time |
|
||||
+------------+-----------------+
|
||||
| 0 | 0.894 |
|
||||
| 1 | 0.995 |
|
||||
| 2 | 1.456 |
|
||||
+------------+-----------------+
|
||||
<strong>Explanation:</strong>
|
||||
There are 3 machines running 2 processes each.
|
||||
Machine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894
|
||||
Machine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995
|
||||
Machine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
|
||||
</pre>
|
72
leetcode/problem/biggest-single-number.html
Normal file
72
leetcode/problem/biggest-single-number.html
Normal file
@@ -0,0 +1,72 @@
|
||||
<p>Table: <code>MyNumbers</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+------+
|
||||
| Column Name | Type |
|
||||
+-------------+------+
|
||||
| num | int |
|
||||
+-------------+------+
|
||||
This table may contain duplicates (In other words, there is no primary key for this table in SQL).
|
||||
Each row of this table contains an integer.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>A <strong>single number</strong> is a number that appeared only once in the <code>MyNumbers</code> table.</p>
|
||||
|
||||
<p>Find the largest <strong>single number</strong>. If there is no <strong>single number</strong>, report <code>null</code>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
<ptable> </ptable>
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
MyNumbers table:
|
||||
+-----+
|
||||
| num |
|
||||
+-----+
|
||||
| 8 |
|
||||
| 8 |
|
||||
| 3 |
|
||||
| 3 |
|
||||
| 1 |
|
||||
| 4 |
|
||||
| 5 |
|
||||
| 6 |
|
||||
+-----+
|
||||
<strong>Output:</strong>
|
||||
+-----+
|
||||
| num |
|
||||
+-----+
|
||||
| 6 |
|
||||
+-----+
|
||||
<strong>Explanation:</strong> The single numbers are 1, 4, 5, and 6.
|
||||
Since 6 is the largest single number, we return it.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
MyNumbers table:
|
||||
+-----+
|
||||
| num |
|
||||
+-----+
|
||||
| 8 |
|
||||
| 8 |
|
||||
| 7 |
|
||||
| 7 |
|
||||
| 3 |
|
||||
| 3 |
|
||||
| 3 |
|
||||
+-----+
|
||||
<strong>Output:</strong>
|
||||
+------+
|
||||
| num |
|
||||
+------+
|
||||
| null |
|
||||
+------+
|
||||
<strong>Explanation:</strong> There are no single numbers in the input table so we return null.
|
||||
</pre>
|
82
leetcode/problem/confirmation-rate.html
Normal file
82
leetcode/problem/confirmation-rate.html
Normal file
@@ -0,0 +1,82 @@
|
||||
<p>Table: <code>Signups</code></p>
|
||||
|
||||
<pre>
|
||||
+----------------+----------+
|
||||
| Column Name | Type |
|
||||
+----------------+----------+
|
||||
| user_id | int |
|
||||
| time_stamp | datetime |
|
||||
+----------------+----------+
|
||||
user_id is the column of unique values for this table.
|
||||
Each row contains information about the signup time for the user with ID user_id.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Table: <code>Confirmations</code></p>
|
||||
|
||||
<pre>
|
||||
+----------------+----------+
|
||||
| Column Name | Type |
|
||||
+----------------+----------+
|
||||
| user_id | int |
|
||||
| time_stamp | datetime |
|
||||
| action | ENUM |
|
||||
+----------------+----------+
|
||||
(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table.
|
||||
user_id is a foreign key (reference column) to the Signups table.
|
||||
action is an ENUM (category) of the type ('confirmed', 'timeout')
|
||||
Each row of this table indicates that the user with ID user_id requested a confirmation message at time_stamp and that confirmation message was either confirmed ('confirmed') or expired without confirming ('timeout').
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>The <strong>confirmation rate</strong> of a user is the number of <code>'confirmed'</code> messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is <code>0</code>. Round the confirmation rate to <strong>two decimal</strong> places.</p>
|
||||
|
||||
<p>Write a solution to find the <strong>confirmation rate</strong> of each user.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Signups table:
|
||||
+---------+---------------------+
|
||||
| user_id | time_stamp |
|
||||
+---------+---------------------+
|
||||
| 3 | 2020-03-21 10:16:13 |
|
||||
| 7 | 2020-01-04 13:57:59 |
|
||||
| 2 | 2020-07-29 23:09:44 |
|
||||
| 6 | 2020-12-09 10:39:37 |
|
||||
+---------+---------------------+
|
||||
Confirmations table:
|
||||
+---------+---------------------+-----------+
|
||||
| user_id | time_stamp | action |
|
||||
+---------+---------------------+-----------+
|
||||
| 3 | 2021-01-06 03:30:46 | timeout |
|
||||
| 3 | 2021-07-14 14:00:00 | timeout |
|
||||
| 7 | 2021-06-12 11:57:29 | confirmed |
|
||||
| 7 | 2021-06-13 12:58:28 | confirmed |
|
||||
| 7 | 2021-06-14 13:59:27 | confirmed |
|
||||
| 2 | 2021-01-22 00:00:00 | confirmed |
|
||||
| 2 | 2021-02-28 23:59:59 | timeout |
|
||||
+---------+---------------------+-----------+
|
||||
<strong>Output:</strong>
|
||||
+---------+-------------------+
|
||||
| user_id | confirmation_rate |
|
||||
+---------+-------------------+
|
||||
| 6 | 0.00 |
|
||||
| 3 | 0.00 |
|
||||
| 7 | 1.00 |
|
||||
| 2 | 0.50 |
|
||||
+---------+-------------------+
|
||||
<strong>Explanation:</strong>
|
||||
User 6 did not request any confirmation messages. The confirmation rate is 0.
|
||||
User 3 made 2 requests and both timed out. The confirmation rate is 0.
|
||||
User 7 made 3 requests and all were confirmed. The confirmation rate is 1.
|
||||
User 2 made 2 requests where one was confirmed and the other timed out. The confirmation rate is 1 / 2 = 0.5.
|
||||
</pre>
|
56
leetcode/problem/count-salary-categories.html
Normal file
56
leetcode/problem/count-salary-categories.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<p>Table: <code>Accounts</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+------+
|
||||
| Column Name | Type |
|
||||
+-------------+------+
|
||||
| account_id | int |
|
||||
| income | int |
|
||||
+-------------+------+
|
||||
account_id is the primary key (column with unique values) for this table.
|
||||
Each row contains information about the monthly income for one bank account.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a solution to calculate the number of bank accounts for each salary category. The salary categories are:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>"Low Salary"</code>: All the salaries <strong>strictly less</strong> than <code>$20000</code>.</li>
|
||||
<li><code>"Average Salary"</code>: All the salaries in the <strong>inclusive</strong> range <code>[$20000, $50000]</code>.</li>
|
||||
<li><code>"High Salary"</code>: All the salaries <strong>strictly greater</strong> than <code>$50000</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>The result table <strong>must</strong> contain all three categories. If there are no accounts in a category, return <code>0</code>.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Accounts table:
|
||||
+------------+--------+
|
||||
| account_id | income |
|
||||
+------------+--------+
|
||||
| 3 | 108939 |
|
||||
| 2 | 12747 |
|
||||
| 8 | 87709 |
|
||||
| 6 | 91796 |
|
||||
+------------+--------+
|
||||
<strong>Output:</strong>
|
||||
+----------------+----------------+
|
||||
| category | accounts_count |
|
||||
+----------------+----------------+
|
||||
| Low Salary | 1 |
|
||||
| Average Salary | 0 |
|
||||
| High Salary | 3 |
|
||||
+----------------+----------------+
|
||||
<strong>Explanation:</strong>
|
||||
Low Salary: Account 2.
|
||||
Average Salary: No accounts.
|
||||
High Salary: Accounts 3, 6, and 8.
|
||||
</pre>
|
67
leetcode/problem/customers-who-bought-all-products.html
Normal file
67
leetcode/problem/customers-who-bought-all-products.html
Normal file
@@ -0,0 +1,67 @@
|
||||
<p>Table: <code>Customer</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+---------+
|
||||
| Column Name | Type |
|
||||
+-------------+---------+
|
||||
| customer_id | int |
|
||||
| product_key | int |
|
||||
+-------------+---------+
|
||||
This table may contain duplicates rows.
|
||||
<code>customer_id</code> is not NULL<code>.</code>
|
||||
product_key is a foreign key (reference column) to <code>Product</code> table.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Table: <code>Product</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+---------+
|
||||
| Column Name | Type |
|
||||
+-------------+---------+
|
||||
| product_key | int |
|
||||
+-------------+---------+
|
||||
product_key is the primary key (column with unique values) for this table.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a solution to report the customer ids from the <code>Customer</code> table that bought all the products in the <code>Product</code> table.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Customer table:
|
||||
+-------------+-------------+
|
||||
| customer_id | product_key |
|
||||
+-------------+-------------+
|
||||
| 1 | 5 |
|
||||
| 2 | 6 |
|
||||
| 3 | 5 |
|
||||
| 3 | 6 |
|
||||
| 1 | 6 |
|
||||
+-------------+-------------+
|
||||
Product table:
|
||||
+-------------+
|
||||
| product_key |
|
||||
+-------------+
|
||||
| 5 |
|
||||
| 6 |
|
||||
+-------------+
|
||||
<strong>Output:</strong>
|
||||
+-------------+
|
||||
| customer_id |
|
||||
+-------------+
|
||||
| 1 |
|
||||
| 3 |
|
||||
+-------------+
|
||||
<strong>Explanation:</strong>
|
||||
The customers who bought all the products (5 and 6) are customers with IDs 1 and 3.
|
||||
</pre>
|
69
leetcode/problem/employee-bonus.html
Normal file
69
leetcode/problem/employee-bonus.html
Normal file
@@ -0,0 +1,69 @@
|
||||
<p>Table: <code>Employee</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+---------+
|
||||
| Column Name | Type |
|
||||
+-------------+---------+
|
||||
| empId | int |
|
||||
| name | varchar |
|
||||
| supervisor | int |
|
||||
| salary | int |
|
||||
+-------------+---------+
|
||||
empId is the column with unique values for this table.
|
||||
Each row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Table: <code>Bonus</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+------+
|
||||
| Column Name | Type |
|
||||
+-------------+------+
|
||||
| empId | int |
|
||||
| bonus | int |
|
||||
+-------------+------+
|
||||
empId is the column of unique values for this table.
|
||||
empId is a foreign key (reference column) to empId from the Employee table.
|
||||
Each row of this table contains the id of an employee and their respective bonus.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a solution to report the name and bonus amount of each employee with a bonus <strong>less than</strong> <code>1000</code>.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Employee table:
|
||||
+-------+--------+------------+--------+
|
||||
| empId | name | supervisor | salary |
|
||||
+-------+--------+------------+--------+
|
||||
| 3 | Brad | null | 4000 |
|
||||
| 1 | John | 3 | 1000 |
|
||||
| 2 | Dan | 3 | 2000 |
|
||||
| 4 | Thomas | 3 | 4000 |
|
||||
+-------+--------+------------+--------+
|
||||
Bonus table:
|
||||
+-------+-------+
|
||||
| empId | bonus |
|
||||
+-------+-------+
|
||||
| 2 | 500 |
|
||||
| 4 | 2000 |
|
||||
+-------+-------+
|
||||
<strong>Output:</strong>
|
||||
+------+-------+
|
||||
| name | bonus |
|
||||
+------+-------+
|
||||
| Brad | null |
|
||||
| John | null |
|
||||
| Dan | 500 |
|
||||
+------+-------+
|
||||
</pre>
|
@@ -0,0 +1,51 @@
|
||||
<p>Table: <code>Employees</code></p>
|
||||
|
||||
<pre>
|
||||
+-------------+----------+
|
||||
| Column Name | Type |
|
||||
+-------------+----------+
|
||||
| employee_id | int |
|
||||
| name | varchar |
|
||||
| manager_id | int |
|
||||
| salary | int |
|
||||
+-------------+----------+
|
||||
In SQL, employee_id is the primary key for this table.
|
||||
This table contains information about the employees, their salary, and the ID of their manager. Some employees do not have a manager (manager_id is null).
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Find the IDs of the employees whose salary is strictly less than <code>$30000</code> and whose manager left the company. When a manager leaves the company, their information is deleted from the <code>Employees</code> table, but the reports still have their <code>manager_id</code> set to the manager that left.</p>
|
||||
|
||||
<p>Return the result table ordered by <code>employee_id</code>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input: </strong>
|
||||
Employees table:
|
||||
+-------------+-----------+------------+--------+
|
||||
| employee_id | name | manager_id | salary |
|
||||
+-------------+-----------+------------+--------+
|
||||
| 3 | Mila | 9 | 60301 |
|
||||
| 12 | Antonella | null | 31000 |
|
||||
| 13 | Emery | null | 67084 |
|
||||
| 1 | Kalel | 11 | 21241 |
|
||||
| 9 | Mikaela | null | 50937 |
|
||||
| 11 | Joziah | 6 | 28485 |
|
||||
+-------------+-----------+------------+--------+
|
||||
<strong>Output:</strong>
|
||||
+-------------+
|
||||
| employee_id |
|
||||
+-------------+
|
||||
| 11 |
|
||||
+-------------+
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
The employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah).
|
||||
Kalel's manager is employee 11, who is still in the company (Joziah).
|
||||
Joziah's manager is employee 6, who left the company because there is no row for employee 6 as it was deleted.
|
||||
</pre>
|
60
leetcode/problem/find-users-with-valid-e-mails.html
Normal file
60
leetcode/problem/find-users-with-valid-e-mails.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<p>Table: <code>Users</code></p>
|
||||
|
||||
<pre>
|
||||
+---------------+---------+
|
||||
| Column Name | Type |
|
||||
+---------------+---------+
|
||||
| user_id | int |
|
||||
| name | varchar |
|
||||
| mail | varchar |
|
||||
+---------------+---------+
|
||||
user_id is the primary key (column with unique values) for this table.
|
||||
This table contains information of the users signed up in a website. Some e-mails are invalid.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a solution to find the users who have <strong>valid emails</strong>.</p>
|
||||
|
||||
<p>A valid e-mail has a prefix name and a domain where:</p>
|
||||
|
||||
<ul>
|
||||
<li><strong>The prefix name</strong> is a string that may contain letters (upper or lower case), digits, underscore <code>'_'</code>, period <code>'.'</code>, and/or dash <code>'-'</code>. The prefix name <strong>must</strong> start with a letter.</li>
|
||||
<li><strong>The domain</strong> is <code>'@leetcode.com'</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Users table:
|
||||
+---------+-----------+-------------------------+
|
||||
| user_id | name | mail |
|
||||
+---------+-----------+-------------------------+
|
||||
| 1 | Winston | winston@leetcode.com |
|
||||
| 2 | Jonathan | jonathanisgreat |
|
||||
| 3 | Annabelle | bella-@leetcode.com |
|
||||
| 4 | Sally | sally.come@leetcode.com |
|
||||
| 5 | Marwan | quarz#2020@leetcode.com |
|
||||
| 6 | David | david69@gmail.com |
|
||||
| 7 | Shapiro | .shapo@leetcode.com |
|
||||
+---------+-----------+-------------------------+
|
||||
<strong>Output:</strong>
|
||||
+---------+-----------+-------------------------+
|
||||
| user_id | name | mail |
|
||||
+---------+-----------+-------------------------+
|
||||
| 1 | Winston | winston@leetcode.com |
|
||||
| 3 | Annabelle | bella-@leetcode.com |
|
||||
| 4 | Sally | sally.come@leetcode.com |
|
||||
+---------+-----------+-------------------------+
|
||||
<strong>Explanation:</strong>
|
||||
The mail of user 2 does not have a domain.
|
||||
The mail of user 5 has the # sign which is not allowed.
|
||||
The mail of user 6 does not have the leetcode domain.
|
||||
The mail of user 7 starts with a period.
|
||||
</pre>
|
Reference in New Issue
Block a user