From 3dbd01c4a15cbb324d9137a385462005e6de8607 Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Wed, 16 Aug 2023 09:32:22 +0700 Subject: [PATCH 1/6] Added tasks 1327, 1341, 1478, 1517, 1633 --- .../readme.md | 85 +++++++++++++++ .../script.sql | 14 +++ .../g1301_1400/s1341_movie_rating/readme.md | 101 ++++++++++++++++++ .../g1301_1400/s1341_movie_rating/script.sql | 13 +++ .../readme.md | 79 ++++++++++++++ .../script.sql | 6 ++ .../Solution.java | 9 ++ .../readme.md | 46 ++++++++ .../readme.md | 65 +++++++++++ .../script.sql | 5 + .../s1529_minimum_suffix_flips/Solution.java | 9 ++ .../s1529_minimum_suffix_flips/readme.md | 55 ++++++++++ .../readme.md | 86 +++++++++++++++ .../script.sql | 8 ++ .../MysqlTest.java | 85 +++++++++++++++ .../s1341_movie_rating/MysqlTest.java | 81 ++++++++++++++ .../MysqlTest.java | 76 +++++++++++++ .../MysqlTest.java | 70 ++++++++++++ .../SolutionTest.java | 13 +++ .../MysqlTest.java | 74 +++++++++++++ 20 files changed, 980 insertions(+) create mode 100644 src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/readme.md create mode 100644 src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/script.sql create mode 100644 src/main/java/g1301_1400/s1341_movie_rating/readme.md create mode 100644 src/main/java/g1301_1400/s1341_movie_rating/script.sql create mode 100644 src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/readme.md create mode 100644 src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/script.sql create mode 100644 src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java create mode 100644 src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md create mode 100644 src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/readme.md create mode 100644 src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql create mode 100644 src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java create mode 100644 src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md create mode 100644 src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/readme.md create mode 100644 src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql create mode 100644 src/test/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/MysqlTest.java create mode 100644 src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java create mode 100644 src/test/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/MysqlTest.java create mode 100644 src/test/java/g1501_1600/s1517_find_users_with_valid_e_mails/MysqlTest.java create mode 100644 src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java create mode 100644 src/test/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/MysqlTest.java diff --git a/src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/readme.md b/src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/readme.md new file mode 100644 index 000000000..a63de1097 --- /dev/null +++ b/src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/readme.md @@ -0,0 +1,85 @@ +1327\. List the Products Ordered in a Period + +Easy + +SQL Schema + +Table: `Products` + + +------------------+---------+ + | Column Name | Type | + +------------------+---------+ + | product_id | int | + | product_name | varchar | + | product_category | varchar | + +------------------+---------+ + +product_id is the primary key for this table. This table contains data about the company's products. + +Table: `Orders` + + +---------------+---------+ + | Column Name | Type | + +---------------+---------+ + | product_id | int | + | order_date | date | + | unit | int | + +---------------+---------+ + +There is no primary key for this table. It may have duplicate rows. product_id is a foreign key to the Products table. unit is the number of products ordered in order_date. + +Write an SQL query to get the names of products that have at least `100` units ordered in **February 2020** and their amount. + +Return result table in **any order**. + +The query result format is in the following example. + +**Example 1:** + +**Input:** Products table: + + +-------------+-----------------------+------------------+ + | product_id | product_name | product_category | + +-------------+-----------------------+------------------+ + | 1 | Leetcode Solutions | Book | + | 2 | Jewels of Stringology | Book | + | 3 | HP | Laptop | + | 4 | Lenovo | Laptop | + | 5 | Leetcode Kit | T-shirt | + +-------------+-----------------------+------------------+ + +Orders table: + + +--------------+--------------+----------+ + | product_id | order_date | unit | + +--------------+--------------+----------+ + | 1 | 2020-02-05 | 60 | + | 1 | 2020-02-10 | 70 | + | 2 | 2020-01-18 | 30 | + | 2 | 2020-02-11 | 80 | + | 3 | 2020-02-17 | 2 | + | 3 | 2020-02-24 | 3 | + | 4 | 2020-03-01 | 20 | + | 4 | 2020-03-04 | 30 | + | 4 | 2020-03-04 | 60 | + | 5 | 2020-02-25 | 50 | + | 5 | 2020-02-27 | 50 | + | 5 | 2020-03-01 | 50 | + +--------------+--------------+----------+ + +**Output:** + + +--------------------+---------+ + | product_name | unit | + +--------------------+---------+ + | Leetcode Solutions | 130 | + | Leetcode Kit | 100 | + +--------------------+---------+ + +**Explanation:** + +Products with product_id = 1 is ordered in February a total of (60 + 70) = 130. + +Products with product_id = 2 is ordered in February a total of 80. Products with product_id = 3 is ordered in February a total of (2 + 3) = 5. + +Products with product_id = 4 was not ordered in February 2020. Products with product_id = 5 is ordered in February a total of (50 + 50) = 100. diff --git a/src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/script.sql b/src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/script.sql new file mode 100644 index 000000000..f963ce521 --- /dev/null +++ b/src/main/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/script.sql @@ -0,0 +1,14 @@ +# Write your MySQL query statement below +# #Easy #Database #2023_08_16_Time_1374_ms_(80.18%)_Space_0B_(100.00%) +SELECT * FROM ( + SELECT + a.product_name, + SUM(b.unit) as unit + FROM Products a + LEFT JOIN Orders b + ON a.product_id = b.product_id + WHERE b.order_date BETWEEN '2020-02-01' AND '2020-02-29' + GROUP BY a.product_name +) AS d +GROUP BY d.product_name +HAVING d.unit >= 100 diff --git a/src/main/java/g1301_1400/s1341_movie_rating/readme.md b/src/main/java/g1301_1400/s1341_movie_rating/readme.md new file mode 100644 index 000000000..14fbc393d --- /dev/null +++ b/src/main/java/g1301_1400/s1341_movie_rating/readme.md @@ -0,0 +1,101 @@ +1341\. Movie Rating + +Medium + +SQL Schema + +Table: `Movies` + + +---------------+---------+ + | Column Name | Type | + +---------------+---------+ + | movie_id | int | + | title | varchar | + +---------------+---------+ + +movie_id is the primary key for this table. title is the name of the movie. + +Table: `Users` + + +---------------+---------+ + | Column Name | Type | + +---------------+---------+ + | user_id | int | + | name | varchar | + +---------------+---------+ + +user_id is the primary key for this table. + +Table: `MovieRating` + + +---------------+---------+ + | Column Name | Type | + +---------------+---------+ + | movie_id | int | + | user_id | int | + | rating | int | + | created_at | date | + +---------------+---------+ + +(movie_id, user_id) is the primary key for this table. This table contains the rating of a movie by a user in their review. created_at is the user's review date. + +Write an SQL query to: + +* Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name. +* Find the movie name with the **highest average** rating in `February 2020`. In case of a tie, return the lexicographically smaller movie name. + +The query result format is in the following example. + +**Example 1:** + +**Input:** Movies table: + + +-------------+--------------+ + | movie_id | title | + +-------------+--------------+ + | 1 | Avengers | + | 2 | Frozen 2 | + | 3 | Joker | + +-------------+--------------+ + +Users table: + + +-------------+--------------+ + | user_id | name | + +-------------+--------------+ + | 1 | Daniel | + | 2 | Monica | + | 3 | Maria | + | 4 | James | + +-------------+--------------+ + +MovieRating table: + + +-------------+--------------+--------------+-------------+ + | movie_id | user_id | rating | created_at | + +-------------+--------------+--------------+-------------+ + | 1 | 1 | 3 | 2020-01-12 | + | 1 | 2 | 4 | 2020-02-11 | + | 1 | 3 | 2 | 2020-02-12 | + | 1 | 4 | 1 | 2020-01-01 | + | 2 | 1 | 5 | 2020-02-17 | + | 2 | 2 | 2 | 2020-02-01 | + | 2 | 3 | 2 | 2020-03-01 | + | 3 | 1 | 3 | 2020-02-22 | + | 3 | 2 | 4 | 2020-02-25 | + +-------------+--------------+--------------+-------------+ + +**Output:** + + +--------------+ + | results | + +--------------+ + | Daniel | + | Frozen 2 | + +--------------+ + +**Explanation:** + +Daniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically. + +Frozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically. diff --git a/src/main/java/g1301_1400/s1341_movie_rating/script.sql b/src/main/java/g1301_1400/s1341_movie_rating/script.sql new file mode 100644 index 000000000..ff1b52230 --- /dev/null +++ b/src/main/java/g1301_1400/s1341_movie_rating/script.sql @@ -0,0 +1,13 @@ +# Write your MySQL query statement below +# #Medium #Database #2023_08_16_Time_2515_ms_(78.94%)_Space_0B_(100.00%) +(SELECT name results +FROM Users as U, MovieRating as MR +WHERE U.user_id = MR.user_id +GROUP BY U.user_id +ORDER BY COUNT(MR.user_id) DESC, name ASC LIMIT 1) +UNION ALL +(SELECT title results +FROM Movies as M, MovieRating as MR +WHERE M.movie_id = MR.movie_id AND created_at BETWEEN '2020-02-01' AND '2020-02-29' +GROUP BY M.movie_id +ORDER BY AVG(rating) DESC, title ASC LIMIT 1) diff --git a/src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/readme.md b/src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/readme.md new file mode 100644 index 000000000..814db0049 --- /dev/null +++ b/src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/readme.md @@ -0,0 +1,79 @@ +1378\. Replace Employee ID With The Unique Identifier + +Easy + +SQL Schema + +Table: `Employees` + + +---------------+---------+ + | Column Name | Type | + +---------------+---------+ + | id | int | + | name | varchar | + +---------------+---------+ + id is the primary key for this table. + Each row of this table contains the id and the name of an employee in a company. + +Table: `EmployeeUNI` + + +---------------+---------+ + | Column Name | Type | + +---------------+---------+ + | id | int | + | unique_id | int | + +---------------+---------+ + (id, unique_id) is the primary key for this table. + Each row of this table contains the id and the corresponding unique id of an employee in the company. + +Write an SQL query to show the **unique ID** of each user, If a user does not have a unique ID replace just show `null`. + +Return the result table in **any** order. + +The query result format is in the following example. + +**Example 1:** + +**Input:**, + + Employees table: + +----+----------+ + | id | name | + +----+----------+ + | 1 | Alice | + | 7 | Bob | + | 11 | Meir | + | 90 | Winston | + | 3 | Jonathan | + +----+----------+ + + EmployeeUNI table: + +----+-----------+ + | id | unique_id | + +----+-----------+ + | 3 | 1 | + | 11 | 2 | + | 90 | 3 | + +----+-----------+ + +**Output:** + + +-----------+----------+ + | unique_id | name | + +-----------+----------+ + | null | Alice | + | null | Bob | + | 2 | Meir | + | 3 | Winston | + | 1 | Jonathan | + +-----------+----------+ + +**Explanation:** + +Alice and Bob do not have a unique ID, We will show null instead. + +The unique ID of Meir is 2. + +The unique ID of Winston is 3. + +The unique ID of Jonathan is 1. \ No newline at end of file diff --git a/src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/script.sql b/src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/script.sql new file mode 100644 index 000000000..7130c6e9e --- /dev/null +++ b/src/main/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/script.sql @@ -0,0 +1,6 @@ +# Write your MySQL query statement below +# #Easy #Database #2023_08_16_Time_2498_ms_(63.60%)_Space_0B_(100.00%) +select u.unique_id, e.name +from Employees e +left join EmployeeUNI u +on e.id = u.id; diff --git a/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java b/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java new file mode 100644 index 000000000..4f0ec1f54 --- /dev/null +++ b/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java @@ -0,0 +1,9 @@ +package g1401_1500.s1460_make_two_arrays_equal_by_reversing_subarrays; + +// #Easy #Array #Hash_Table #Sorting + +public class Solution { + public String decode(String value) { + return value; + } +} diff --git a/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md b/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md new file mode 100644 index 000000000..f4fe1391e --- /dev/null +++ b/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md @@ -0,0 +1,46 @@ +1460\. Make Two Arrays Equal by Reversing Sub-arrays + +Easy + +You are given two integer arrays of equal length `target` and `arr`. In one step, you can select any **non-empty sub-array** of `arr` and reverse it. You are allowed to make any number of steps. + +Return `true` _if you can make_ `arr` _equal to_ `target`_or_ `false` _otherwise_. + +**Example 1:** + +**Input:** target = [1,2,3,4], arr = [2,4,1,3] + +**Output:** true + +**Explanation:** You can follow the next steps to convert arr to target: + +1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3] + +2- Reverse sub-array [4,2], arr becomes [1,2,4,3] + +3- Reverse sub-array [4,3], arr becomes [1,2,3,4] + +There are multiple ways to convert arr to target, this is not the only way to do so. + +**Example 2:** + +**Input:** target = [7], arr = [7] + +**Output:** true + +**Explanation:** arr is equal to target without any reverses. + +**Example 3:** + +**Input:** target = [3,7,9], arr = [3,7,11] + +**Output:** false + +**Explanation:** arr does not have value 9 and it can never be converted to target. + +**Constraints:** + +* `target.length == arr.length` +* `1 <= target.length <= 1000` +* `1 <= target[i] <= 1000` +* `1 <= arr[i] <= 1000` \ No newline at end of file diff --git a/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/readme.md b/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/readme.md new file mode 100644 index 000000000..e015dca22 --- /dev/null +++ b/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/readme.md @@ -0,0 +1,65 @@ +1517\. Find Users With Valid E-Mails + +Easy + +SQL Schema + +Table: `Users` + + +---------------+---------+ + | Column Name | Type | + +---------------+---------+ + | user_id | int | + | name | varchar | + | mail | varchar | + +---------------+---------+ + user_id is the primary key for this table. + This table contains information of the users signed up in a website. Some e-mails are invalid. + +Write an SQL query to find the users who have **valid emails**. + +A valid e-mail has a prefix name and a domain where: + +* **The prefix name** is a string that may contain letters (upper or lower case), digits, underscore `'_'`, period `'.'`, and/or dash `'-'`. The prefix name **must** start with a letter. +* **The domain** is `'@leetcode.com'`. + +Return the result table in **any order**. + +The query result format is in the following example. + +**Example 1:** + +**Input:** + + 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 | + +---------+-----------+-------------------------+ + +**Output:** + + +---------+-----------+-------------------------+ + | user_id | name | mail | + +---------+-----------+-------------------------+ + | 1 | Winston | winston@leetcode.com | + | 3 | Annabelle | bella-@leetcode.com | + | 4 | Sally | sally.come@leetcode.com | + +---------+-----------+-------------------------+ + +**Explanation:** + +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. \ No newline at end of file diff --git a/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql b/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql new file mode 100644 index 000000000..38d9841b8 --- /dev/null +++ b/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql @@ -0,0 +1,5 @@ +# Write your MySQL query statement below +# #Easy #Database #2023_08_16_Time_1356_ms_(75.95%)_Space_0B_(100.00%) +SELECT * +FROM Users +WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com' \ No newline at end of file diff --git a/src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java b/src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java new file mode 100644 index 000000000..c50927c66 --- /dev/null +++ b/src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java @@ -0,0 +1,9 @@ +package g1501_1600.s1529_minimum_suffix_flips; + +// #Medium #String #Greedy + +public class Solution { + public String decode(String value) { + return value; + } +} diff --git a/src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md b/src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md new file mode 100644 index 000000000..1ac764469 --- /dev/null +++ b/src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md @@ -0,0 +1,55 @@ +1529\. Minimum Suffix Flips + +Medium + +You are given a **0-indexed** binary string `target` of length `n`. You have another binary string `s` of length `n` that is initially set to all zeros. You want to make `s` equal to `target`. + +In one operation, you can pick an index `i` where `0 <= i < n` and flip all bits in the **inclusive** range `[i, n - 1]`. Flip means changing `'0'` to `'1'` and `'1'` to `'0'`. + +Return _the minimum number of operations needed to make_ `s` _equal to_ `target`. + +**Example 1:** + +**Input:** target = "10111" + +**Output:** 3 + +**Explanation:** Initially, s = "00000". + +Choose index i = 2: "00000" -> "00111" + +Choose index i = 0: "00111" -> "11000" + +Choose index i = 1: "11000" -> "10111" + +We need at least 3 flip operations to form target. + +**Example 2:** + +**Input:** target = "101" + +**Output:** 3 + +**Explanation:** Initially, s = "000". + +Choose index i = 0: "000" -> "111" + +Choose index i = 1: "111" -> "100" + +Choose index i = 2: "100" -> "101" + +We need at least 3 flip operations to form target. + +**Example 3:** + +**Input:** target = "00000" + +**Output:** 0 + +**Explanation:** We do not need any operations since the initial s already equals target. + +**Constraints:** + +* `n == target.length` +* 1 <= n <= 105 +* `target[i]` is either `'0'` or `'1'`. \ No newline at end of file diff --git a/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/readme.md b/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/readme.md new file mode 100644 index 000000000..abb6cf6c5 --- /dev/null +++ b/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/readme.md @@ -0,0 +1,86 @@ +1633\. Percentage of Users Attended a Contest + +Easy + +SQL Schema + +Table: `Users` + + +-------------+---------+ + | Column Name | Type | + +-------------+---------+ + | user_id | int | + | user_name | varchar | + +-------------+---------+ + +user_id is the primary key for this table. Each row of this table contains the name and the id of a user. + +Table: `Register` + + +-------------+---------+ + | Column Name | Type | + +-------------+---------+ + | contest_id | int | + | user_id | int | + +-------------+---------+ + +(contest_id, user_id) is the primary key for this table. Each row of this table contains the id of a user and the contest they registered into. + +Write an SQL query to find the percentage of the users registered in each contest rounded to **two decimals**. + +Return the result table ordered by `percentage` in **descending order**. In case of a tie, order it by `contest_id` in **ascending order**. + +The query result format is in the following example. + +**Example 1:** + +**Input:** Users table: + + +---------+-----------+ + | user_id | user_name | + +---------+-----------+ + | 6 | Alice | + | 2 | Bob | + | 7 | Alex | + +---------+-----------+ + +Register table: + + +------------+---------+ + | contest_id | user_id | + +------------+---------+ + | 215 | 6 | + | 209 | 2 | + | 208 | 2 | + | 210 | 6 | + | 208 | 6 | + | 209 | 7 | + | 209 | 6 | + | 215 | 7 | + | 208 | 7 | + | 210 | 2 | + | 207 | 2 | + | 210 | 7 | + +------------+---------+ + +**Output:** + + +------------+------------+ + | contest_id | percentage | + +------------+------------+ + | 208 | 100.0 | + | 209 | 100.0 | + | 210 | 100.0 | + | 215 | 66.67 | + | 207 | 33.33 | + +------------+------------+ + +**Explanation:** + +All the users registered in contests 208, 209, and 210. + +The percentage is 100% and we sort them in the answer table by contest_id in ascending order. + +Alice and Alex registered in contest 215 and the percentage is ((2/3) * 100) = 66.67% + +Bob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33% \ No newline at end of file diff --git a/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql b/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql new file mode 100644 index 000000000..51a0e8a45 --- /dev/null +++ b/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql @@ -0,0 +1,8 @@ +# Write your MySQL query statement below +# #Easy #Database #2023_08_16_Time_1550_ms_(95.68%)_Space_0B_(100.00%) +SELECT r.contest_id, +ROUND(COUNT(r.user_id) / (SELECT COUNT(user_id) FROM Users) * 100,2) as percentage +FROM Users u LEFT JOIN Register r ON u.user_id=r.user_id +WHERE contest_id IS NOT NULL +GROUP BY r.contest_id +ORDER BY percentage DESC, contest_id ASC \ No newline at end of file diff --git a/src/test/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/MysqlTest.java b/src/test/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/MysqlTest.java new file mode 100644 index 000000000..62ca61f06 --- /dev/null +++ b/src/test/java/g1301_1400/s1327_list_the_products_ordered_in_a_period/MysqlTest.java @@ -0,0 +1,85 @@ +package g1301_1400.s1327_list_the_products_ordered_in_a_period; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.stream.Collectors; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.zapodot.junit.db.annotations.EmbeddedDatabase; +import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; +import org.zapodot.junit.db.common.CompatibilityMode; + +@EmbeddedDatabaseTest( + compatibilityMode = CompatibilityMode.MySQL, + initialSqls = + "CREATE TABLE Products(product_id INTEGER, product_name VARCHAR, product_category VARCHAR); " + + "INSERT INTO Products(product_id, product_name, product_category)" + + " VALUES (1, 'Leetcode Solutions', 'Book'); " + + "INSERT INTO Products(product_id, product_name, product_category)" + + " VALUES (2, 'Jewels of Stringology', 'Book'); " + + "INSERT INTO Products(product_id, product_name, product_category)" + + " VALUES (3, 'HP', 'Laptop'); " + + "INSERT INTO Products(product_id, product_name, product_category)" + + " VALUES (4, 'Lenovo', 'Laptop'); " + + "INSERT INTO Products(product_id, product_name, product_category)" + + " VALUES (5, 'Leetcode Kit', 'T-shirt'); " + + "CREATE TABLE Orders(product_id INTEGER, order_date DATE, unit INTEGER); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (1, '2020-02-05', 60); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (1, '2020-02-10', 70); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (2, '2020-01-18', 30); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (2, '2020-02-11', 80); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (3 , '2020-02-17', 2); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (3, '2020-02-24', 3); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (4, '2020-03-01', 20); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (4, '2020-03-04', 30); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (4, '2020-03-04', 60); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (5, '2020-02-25', 50); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (5, '2020-02-27', 50); " + + "INSERT INTO Orders(product_id, order_date, unit)" + + " VALUES (5, '2020-03-01', 50); ") +class MysqlTest { + @Test + void testScript(@EmbeddedDatabase DataSource dataSource) + throws SQLException, FileNotFoundException { + try (final Connection connection = dataSource.getConnection()) { + try (final Statement statement = connection.createStatement(); + final ResultSet resultSet = + statement.executeQuery( + new BufferedReader( + new FileReader( + "src/main/java/g1301_1400/" + + "s1327_list_the_products_ordered_" + + "in_a_period/script.sql")) + .lines() + .collect(Collectors.joining("\n")) + .replaceAll("#.*?\\r?\\n", ""))) { + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("Leetcode Kit")); + assertThat(resultSet.getInt(2), equalTo(100)); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("Leetcode Solutions")); + assertThat(resultSet.getInt(2), equalTo(130)); + assertThat(resultSet.next(), equalTo(false)); + } + } + } +} diff --git a/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java b/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java new file mode 100644 index 000000000..552982831 --- /dev/null +++ b/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java @@ -0,0 +1,81 @@ +package g1301_1400.s1341_movie_rating; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.stream.Collectors; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.zapodot.junit.db.annotations.EmbeddedDatabase; +import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; +import org.zapodot.junit.db.common.CompatibilityMode; + +@EmbeddedDatabaseTest( + compatibilityMode = CompatibilityMode.MySQL, + initialSqls = + "CREATE TABLE Movies(movie_id INTEGER, title VARCHAR); " + + "INSERT INTO Movies(movie_id, title)" + + " VALUES (1, 'Avengers'); " + + "INSERT INTO Movies(movie_id, title)" + + " VALUES (2, 'Frozen 2'); " + + "INSERT INTO Movies(movie_id, title)" + + " VALUES (3, 'Joker'); " + + "CREATE TABLE Users(user_id INTEGER, name VARCHAR); " + + "INSERT INTO Users(user_id, name)" + + " VALUES (1, 'Daniel'); " + + "INSERT INTO Users(user_id, name)" + + " VALUES (2, 'Monica'); " + + "INSERT INTO Users(user_id, name)" + + " VALUES (3, 'Maria'); " + + "INSERT INTO Users(user_id, name)" + + " VALUES (4, 'James'); " + + "CREATE TABLE MovieRating(movie_id INTEGER, user_id INTEGER, rating INTEGER, created_at DATE); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (1, 1, 3, '2020-01-12'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (1, 2, 4, '2020-02-11'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (1, 3, 2, '2020-02-12'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (1, 4, 1, '2020-01-01'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (2, 1, 5, '2020-02-17'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (2, 2, 2, '2020-02-01'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (2, 3, 2, '2020-03-01'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (3, 1, 3, '2020-02-22'); " + + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + + " VALUES (3, 2, 4, '2020-02-25'); ") +class MysqlTest { + @Test + void testScript(@EmbeddedDatabase DataSource dataSource) + throws SQLException, FileNotFoundException { + try (final Connection connection = dataSource.getConnection()) { + try (final Statement statement = connection.createStatement(); + final ResultSet resultSet = + statement.executeQuery( + new BufferedReader( + new FileReader( + "src/main/java/g1301_1400/" + + "s1341_movie_rating/script.sql")) + .lines() + .collect(Collectors.joining("\n")) + .replaceAll("#.*?\\r?\\n", ""))) { + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("Daniel")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("Frozen 2")); + assertThat(resultSet.next(), equalTo(false)); + } + } + } +} diff --git a/src/test/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/MysqlTest.java b/src/test/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/MysqlTest.java new file mode 100644 index 000000000..882ec7fc1 --- /dev/null +++ b/src/test/java/g1301_1400/s1378_replace_employee_id_with_the_unique_identifier/MysqlTest.java @@ -0,0 +1,76 @@ +package g1301_1400.s1378_replace_employee_id_with_the_unique_identifier; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.stream.Collectors; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.zapodot.junit.db.annotations.EmbeddedDatabase; +import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; +import org.zapodot.junit.db.common.CompatibilityMode; + +@EmbeddedDatabaseTest( + compatibilityMode = CompatibilityMode.MySQL, + initialSqls = + "CREATE TABLE Employees(id INTEGER, name VARCHAR); " + + "INSERT INTO Employees(id, name)" + + " VALUES (1, 'Alice'); " + + "INSERT INTO Employees(id, name)" + + " VALUES (7, 'Bob'); " + + "INSERT INTO Employees(id, name)" + + " VALUES (11, 'Meir'); " + + "INSERT INTO Employees(id, name)" + + " VALUES (90, 'Winston'); " + + "INSERT INTO Employees(id, name)" + + " VALUES (3, 'Jonathan'); " + + "CREATE TABLE EmployeeUNI(id INTEGER, unique_id INTEGER); " + + "INSERT INTO EmployeeUNI(id, unique_id)" + + " VALUES (3, 1); " + + "INSERT INTO EmployeeUNI(id, unique_id)" + + " VALUES (11, 2); " + + "INSERT INTO EmployeeUNI(id, unique_id)" + + " VALUES (90, 3); ") +class MysqlTest { + @Test + void testScript(@EmbeddedDatabase DataSource dataSource) + throws SQLException, FileNotFoundException { + try (final Connection connection = dataSource.getConnection()) { + try (final Statement statement = connection.createStatement(); + final ResultSet resultSet = + statement.executeQuery( + new BufferedReader( + new FileReader( + "src/main/java/g1301_1400/" + + "s1378_replace_employee_id_with" + + "_the_unique_identifier/script.sql")) + .lines() + .collect(Collectors.joining("\n")) + .replaceAll("#.*?\\r?\\n", ""))) { + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo(null)); + assertThat(resultSet.getNString(2), equalTo("Alice")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo(null)); + assertThat(resultSet.getNString(2), equalTo("Bob")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("2")); + assertThat(resultSet.getNString(2), equalTo("Meir")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("3")); + assertThat(resultSet.getNString(2), equalTo("Winston")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("1")); + assertThat(resultSet.getNString(2), equalTo("Jonathan")); + assertThat(resultSet.next(), equalTo(false)); + } + } + } +} diff --git a/src/test/java/g1501_1600/s1517_find_users_with_valid_e_mails/MysqlTest.java b/src/test/java/g1501_1600/s1517_find_users_with_valid_e_mails/MysqlTest.java new file mode 100644 index 000000000..9477be2bd --- /dev/null +++ b/src/test/java/g1501_1600/s1517_find_users_with_valid_e_mails/MysqlTest.java @@ -0,0 +1,70 @@ +package g1501_1600.s1517_find_users_with_valid_e_mails; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.stream.Collectors; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.zapodot.junit.db.annotations.EmbeddedDatabase; +import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; +import org.zapodot.junit.db.common.CompatibilityMode; + +@EmbeddedDatabaseTest( + compatibilityMode = CompatibilityMode.MySQL, + initialSqls = + "CREATE TABLE Users(user_id INTEGER PRIMARY KEY, name" + + " VARCHAR, mail VARCHAR); " + + "INSERT INTO Users(user_id, name, mail)" + + " VALUES (1, 'Winston', 'winston@leetcode.com'); " + + "INSERT INTO Users(user_id, name, mail)" + + " VALUES (2, 'Jonathan', 'jonathanisgreat'); " + + "INSERT INTO Users(user_id, name, mail)" + + " VALUES (3, 'Annabelle', 'bella-@leetcode.com'); " + + "INSERT INTO Users(user_id, name, mail)" + + " VALUES (4, 'Sally', 'sally.come@leetcode.com'); " + + "INSERT INTO Users(user_id, name, mail)" + + " VALUES (5, 'Marwan', 'quarz#2020@leetcode.com'); " + + "INSERT INTO Users(user_id, name, mail)" + + " VALUES (6, 'David', 'david69@gmail.com'); " + + "INSERT INTO Users(user_id, name, mail)" + + " VALUES (7, 'Shapiro', '.shapo@leetcode.com'); ") +class MysqlTest { + @Test + void testScript(@EmbeddedDatabase DataSource dataSource) + throws SQLException, FileNotFoundException { + try (final Connection connection = dataSource.getConnection()) { + try (final Statement statement = connection.createStatement(); + final ResultSet resultSet = + statement.executeQuery( + new BufferedReader( + new FileReader( + "src/main/java/g1501_1600/" + + "s1517_find_users_with_valid_e_mails/script.sql")) + .lines() + .collect(Collectors.joining("\n")) + .replaceAll("#.*?\\r?\\n", ""))) { + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(1)); + assertThat(resultSet.getNString(2), equalTo("Winston")); + assertThat(resultSet.getNString(3), equalTo("winston@leetcode.com")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(3)); + assertThat(resultSet.getNString(2), equalTo("Annabelle")); + assertThat(resultSet.getNString(3), equalTo("bella-@leetcode.com")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(4)); + assertThat(resultSet.getNString(2), equalTo("Sally")); + assertThat(resultSet.getNString(3), equalTo("sally.come@leetcode.com")); + assertThat(resultSet.next(), equalTo(false)); + } + } + } +} diff --git a/src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java b/src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java new file mode 100644 index 000000000..33b2b8aa2 --- /dev/null +++ b/src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java @@ -0,0 +1,13 @@ +package g1501_1600.s1529_minimum_suffix_flips; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void test() { + assertThat(new Solution().decode(""), equalTo("")); + } +} diff --git a/src/test/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/MysqlTest.java b/src/test/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/MysqlTest.java new file mode 100644 index 000000000..7a28f9a7a --- /dev/null +++ b/src/test/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/MysqlTest.java @@ -0,0 +1,74 @@ +package g1601_1700.s1633_percentage_of_users_attended_a_contest; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.stream.Collectors; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.zapodot.junit.db.annotations.EmbeddedDatabase; +import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; +import org.zapodot.junit.db.common.CompatibilityMode; + +@EmbeddedDatabaseTest( + compatibilityMode = CompatibilityMode.MySQL, + initialSqls = + "CREATE TABLE Users(user_id INTEGER, user_name VARCHAR); " + + "INSERT INTO Users(user_id, user_name) VALUES (6, 'Alice'); " + + "INSERT INTO Users(user_id, user_name) VALUES (2, 'Bob'); " + + "INSERT INTO Users(user_id, user_name) VALUES (7, 'Alex'); " + + "CREATE TABLE Register(contest_id INTEGER, user_id INTEGER); " + + "INSERT INTO Register (contest_id, user_id) VALUES (215, 6); " + + "INSERT INTO Register (contest_id, user_id) VALUES (209, 2); " + + "INSERT INTO Register (contest_id, user_id) VALUES (208, 2); " + + "INSERT INTO Register (contest_id, user_id) VALUES (210, 6); " + + "INSERT INTO Register (contest_id, user_id) VALUES (208, 6); " + + "INSERT INTO Register (contest_id, user_id) VALUES (209, 7); " + + "INSERT INTO Register (contest_id, user_id) VALUES (209, 6); " + + "INSERT INTO Register (contest_id, user_id) VALUES (215, 7); " + + "INSERT INTO Register (contest_id, user_id) VALUES (208, 7); " + + "INSERT INTO Register (contest_id, user_id) VALUES (210, 2); " + + "INSERT INTO Register (contest_id, user_id) VALUES (207, 2); " + + "INSERT INTO Register (contest_id, user_id) VALUES (210, 7); ") +class MysqlTest { + @Test + void testScript(@EmbeddedDatabase DataSource dataSource) + throws SQLException, FileNotFoundException { + try (final Connection connection = dataSource.getConnection()) { + try (final Statement statement = connection.createStatement(); + final ResultSet resultSet = + statement.executeQuery( + new BufferedReader( + new FileReader( + "src/main/java/g1601_1700/s1633_percentage" + + "_of_users_attended_a_contest/script.sql")) + .lines() + .collect(Collectors.joining("\n")) + .replaceAll("#.*?\\r?\\n", ""))) { + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(208)); + assertThat(resultSet.getDouble(2), equalTo(100.0)); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(209)); + assertThat(resultSet.getDouble(2), equalTo(100.0)); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(210)); + assertThat(resultSet.getDouble(2), equalTo(100.0)); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(207)); + assertThat(resultSet.getDouble(2), equalTo(0.0)); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getInt(1), equalTo(215)); + assertThat(resultSet.getDouble(2), equalTo(0.0)); + assertThat(resultSet.next(), equalTo(false)); + } + } + } +} From 53cd6eff3c39e5e5acbc803b44aee338d92b698d Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Wed, 16 Aug 2023 09:33:47 +0700 Subject: [PATCH 2/6] Update MysqlTest.java --- src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java b/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java index 552982831..332e9e630 100644 --- a/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java +++ b/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java @@ -36,7 +36,8 @@ + " VALUES (3, 'Maria'); " + "INSERT INTO Users(user_id, name)" + " VALUES (4, 'James'); " - + "CREATE TABLE MovieRating(movie_id INTEGER, user_id INTEGER, rating INTEGER, created_at DATE); " + + "CREATE TABLE MovieRating(movie_id INTEGER, user_id INTEGER," + + " rating INTEGER, created_at DATE); " + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + " VALUES (1, 1, 3, '2020-01-12'); " + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" From 3d81810d9f5837bfc13bfd4ad6cc5009f57e5062 Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Wed, 16 Aug 2023 09:35:32 +0700 Subject: [PATCH 3/6] Update MysqlTest.java --- src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java b/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java index 332e9e630..cff48b0b0 100644 --- a/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java +++ b/src/test/java/g1301_1400/s1341_movie_rating/MysqlTest.java @@ -36,8 +36,8 @@ + " VALUES (3, 'Maria'); " + "INSERT INTO Users(user_id, name)" + " VALUES (4, 'James'); " - + "CREATE TABLE MovieRating(movie_id INTEGER, user_id INTEGER," + - " rating INTEGER, created_at DATE); " + + "CREATE TABLE MovieRating(movie_id INTEGER, user_id INTEGER," + + " rating INTEGER, created_at DATE); " + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" + " VALUES (1, 1, 3, '2020-01-12'); " + "INSERT INTO MovieRating(movie_id, user_id, rating, created_at)" From d5b49588c45d4f5a024fdcfd4da6fa410db22335 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Wed, 16 Aug 2023 05:59:39 +0300 Subject: [PATCH 4/6] Update script.sql --- .../g1501_1600/s1517_find_users_with_valid_e_mails/script.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql b/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql index 38d9841b8..ec224a274 100644 --- a/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql +++ b/src/main/java/g1501_1600/s1517_find_users_with_valid_e_mails/script.sql @@ -2,4 +2,4 @@ # #Easy #Database #2023_08_16_Time_1356_ms_(75.95%)_Space_0B_(100.00%) SELECT * FROM Users -WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com' \ No newline at end of file +WHERE mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com' From 4fb10c7cc1dbc91edb07712053f07efe9acdf8d2 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Wed, 16 Aug 2023 06:00:05 +0300 Subject: [PATCH 5/6] Update script.sql --- .../s1633_percentage_of_users_attended_a_contest/script.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql b/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql index 51a0e8a45..73d7ba1ba 100644 --- a/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql +++ b/src/main/java/g1601_1700/s1633_percentage_of_users_attended_a_contest/script.sql @@ -5,4 +5,4 @@ ROUND(COUNT(r.user_id) / (SELECT COUNT(user_id) FROM Users) * 100,2) as percenta FROM Users u LEFT JOIN Register r ON u.user_id=r.user_id WHERE contest_id IS NOT NULL GROUP BY r.contest_id -ORDER BY percentage DESC, contest_id ASC \ No newline at end of file +ORDER BY percentage DESC, contest_id ASC From 16a867bdb0c0773b7a2668d74bb24c5ec6f0d56b Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Wed, 16 Aug 2023 10:07:10 +0700 Subject: [PATCH 6/6] update --- .../Solution.java | 9 --- .../readme.md | 46 ---------------- .../s1529_minimum_suffix_flips/Solution.java | 9 --- .../s1529_minimum_suffix_flips/readme.md | 55 ------------------- .../SolutionTest.java | 13 ----- 5 files changed, 132 deletions(-) delete mode 100644 src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java delete mode 100644 src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md delete mode 100644 src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java delete mode 100644 src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md delete mode 100644 src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java diff --git a/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java b/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java deleted file mode 100644 index 4f0ec1f54..000000000 --- a/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/Solution.java +++ /dev/null @@ -1,9 +0,0 @@ -package g1401_1500.s1460_make_two_arrays_equal_by_reversing_subarrays; - -// #Easy #Array #Hash_Table #Sorting - -public class Solution { - public String decode(String value) { - return value; - } -} diff --git a/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md b/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md deleted file mode 100644 index f4fe1391e..000000000 --- a/src/main/java/g1401_1500/s1460_make_two_arrays_equal_by_reversing_subarrays/readme.md +++ /dev/null @@ -1,46 +0,0 @@ -1460\. Make Two Arrays Equal by Reversing Sub-arrays - -Easy - -You are given two integer arrays of equal length `target` and `arr`. In one step, you can select any **non-empty sub-array** of `arr` and reverse it. You are allowed to make any number of steps. - -Return `true` _if you can make_ `arr` _equal to_ `target`_or_ `false` _otherwise_. - -**Example 1:** - -**Input:** target = [1,2,3,4], arr = [2,4,1,3] - -**Output:** true - -**Explanation:** You can follow the next steps to convert arr to target: - -1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3] - -2- Reverse sub-array [4,2], arr becomes [1,2,4,3] - -3- Reverse sub-array [4,3], arr becomes [1,2,3,4] - -There are multiple ways to convert arr to target, this is not the only way to do so. - -**Example 2:** - -**Input:** target = [7], arr = [7] - -**Output:** true - -**Explanation:** arr is equal to target without any reverses. - -**Example 3:** - -**Input:** target = [3,7,9], arr = [3,7,11] - -**Output:** false - -**Explanation:** arr does not have value 9 and it can never be converted to target. - -**Constraints:** - -* `target.length == arr.length` -* `1 <= target.length <= 1000` -* `1 <= target[i] <= 1000` -* `1 <= arr[i] <= 1000` \ No newline at end of file diff --git a/src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java b/src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java deleted file mode 100644 index c50927c66..000000000 --- a/src/main/java/g1501_1600/s1529_minimum_suffix_flips/Solution.java +++ /dev/null @@ -1,9 +0,0 @@ -package g1501_1600.s1529_minimum_suffix_flips; - -// #Medium #String #Greedy - -public class Solution { - public String decode(String value) { - return value; - } -} diff --git a/src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md b/src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md deleted file mode 100644 index 1ac764469..000000000 --- a/src/main/java/g1501_1600/s1529_minimum_suffix_flips/readme.md +++ /dev/null @@ -1,55 +0,0 @@ -1529\. Minimum Suffix Flips - -Medium - -You are given a **0-indexed** binary string `target` of length `n`. You have another binary string `s` of length `n` that is initially set to all zeros. You want to make `s` equal to `target`. - -In one operation, you can pick an index `i` where `0 <= i < n` and flip all bits in the **inclusive** range `[i, n - 1]`. Flip means changing `'0'` to `'1'` and `'1'` to `'0'`. - -Return _the minimum number of operations needed to make_ `s` _equal to_ `target`. - -**Example 1:** - -**Input:** target = "10111" - -**Output:** 3 - -**Explanation:** Initially, s = "00000". - -Choose index i = 2: "00000" -> "00111" - -Choose index i = 0: "00111" -> "11000" - -Choose index i = 1: "11000" -> "10111" - -We need at least 3 flip operations to form target. - -**Example 2:** - -**Input:** target = "101" - -**Output:** 3 - -**Explanation:** Initially, s = "000". - -Choose index i = 0: "000" -> "111" - -Choose index i = 1: "111" -> "100" - -Choose index i = 2: "100" -> "101" - -We need at least 3 flip operations to form target. - -**Example 3:** - -**Input:** target = "00000" - -**Output:** 0 - -**Explanation:** We do not need any operations since the initial s already equals target. - -**Constraints:** - -* `n == target.length` -* 1 <= n <= 105 -* `target[i]` is either `'0'` or `'1'`. \ No newline at end of file diff --git a/src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java b/src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java deleted file mode 100644 index 33b2b8aa2..000000000 --- a/src/test/java/g1501_1600/s1529_minimum_suffix_flips/SolutionTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package g1501_1600.s1529_minimum_suffix_flips; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.jupiter.api.Test; - -class SolutionTest { - @Test - void test() { - assertThat(new Solution().decode(""), equalTo("")); - } -}