[Leetcode 1084] Sales Analysis III
原题说明
Table: Product
+————–+———+
| Column Name | Type |
+————–+———+
| product_id | int |
| product_name | varchar |
| unit_price | int |
+————–+———+
product_id is the primary key of this table.
Table: Sales
+————-+———+
| Column Name | Type |
+————-+———+
| seller_id | int |
| product_id | int |
| buyer_id | int |
| sale_date | date |
| quantity | int |
| price | int |
+—— ——+———+
This table has no primary key, it can have repeated rows.
product_id is a foreign key to Product table.
Write an SQL query that reports the products that were only sold in spring 2019. That is, between 2019-01-01 and 2019-03-31 inclusive.
The query result format is in the following example:
Product table:
+————+————–+————+
| product_id | product_name | unit_price |
+————+————–+————+
| 1 | S8 | 1000 |
| 2 | G4 | 800 |
| 3 | iPhone | 1400 |
+————+————–+————+
Salestable:
+———–+————+———-+————+———-+——-+
| seller_id | product_id | buyer_id | sale_date | quantity | price |
+———–+————+———-+————+———-+——-+
| 1 | 1 | 1 | 2019-01-21 | 2 | 2000 |
| 1 | 2 | 2 | 2019-02-17 | 1 | 800 |
| 2 | 2 | 3 | 2019-06-02 | 1 | 800 |
| 3 | 3 | 4 | 2019-05-13 | 2 | 2800 |
+———–+————+———-+————+———-+——-+Result table:
+————-+————–+
| product_id | product_name |
+————-+————–+
| 1 | S8 |
+————-+————–+
The product with id 1 was only sold in spring 2019 while the other two were sold after.
[Leetcode 1082] Sales Analysis I
原题说明
Table: Product
+————–+———+
| Column Name | Type |
+————–+———+
| product_id | int |
| product_name | varchar |
| unit_price | int |
+————–+———+
product_id is the primary key of this table.
Table: Sales
+————-+———+
| Column Name | Type |
+————-+———+
| seller_id | int |
| product_id | int |
| buyer_id | int |
| sale_date | date |
| quantity | int |
| price | int |
+—— ——+———+
This table has no primary key, it can have repeated rows.
product_id is a foreign key to Product table.
Write an SQL query that reports the best seller by total sales price, If there is a tie, report them all.
The query result format is in the following example:
Product table:
+————+————–+————+
| product_id | product_name | unit_price |
+————+————–+————+
| 1 | S8 | 1000 |
| 2 | G4 | 800 |
| 3 | iPhone | 1400 |
+————+————–+————+
Salestable:
+———–+————+———-+————+———-+——-+
| seller_id | product_id | buyer_id | sale_date | quantity | price |
+———–+————+———-+————+———-+——-+
| 1 | 1 | 1 | 2019-01-21 | 2 | 2000 |
| 1 | 2 | 2 | 2019-02-17 | 1 | 800 |
| 2 | 2 | 3 | 2019-06-02 | 1 | 800 |
| 3 | 3 | 4 | 2019-05-13 | 2 | 2800 |
+———–+————+———-+————+———-+——-+Result table:
+————-+
| seller_id |
+————-+
| 1 |
| 3 |
+————-+
Both sellers with id 1 and 3 sold products with the most total price of 2800.
[Leetcode 1080] Insufficient Nodes in Root to Leaf Paths
原题说明
Given the root of a binary tree, consider all root to leaf paths: paths from the root to any leaf. (A leaf is a node with no children.)
A node is insufficient if every such root to leaf path intersecting this node has sum strictly less than limit.
Delete all insufficient nodes simultaneously, and return the root of the resulting binary tree.
Example 1:
Input: root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1
Output: [1,2,3,4,null,null,7,8,9,null,14]
Example 2:
Input: root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22
Output: [5,4,8,11,null,17,4,7,null,null,null,5]
Example 3:
Input: root = [1,2,-3,-5,null,4,null], limit = -1
Output: [1,null,-3,4]
Note:
- The given tree will have between
1and5000nodes. -10^5 <= node.val <= 10^5-10^9 <= limit <= 10^9
[Leetcode 1078] Occurrences After Bigram
原题说明
Given words first and second, consider occurrences in some text of the form “first second third“, where second comes immediately after first, and third comes immediately after second.
For each such occurrence, add “third“ to the answer, and return the answer.
Example 1:
Input: text = “alice is a good girl she is a good student”, first = “a”, second = “good”
Output: [“girl”,”student”]
Example 2:
Input: text = “we will we will rock you”, first = “we”, second = “will”
Output: [“we”,”rock”]
Note:
1 <= text.length <= 1000textconsists of space separated words, where each word consists of lowercase English letters.1 <= first.length, second.length <= 10firstandsecondconsist of lowercase English letters.
[Leetcode 1079] Letter Tile Possibilities
原题说明
You have a set of tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make.
Example 1:
Input: “AAB”
Output: 8
Explanation: The possible sequences are “A”, “B”, “AA”, “AB”, “BA”, “AAB”, “ABA”, “BAA”.
Example 2:
Input: “AAABBC”
Output: 188
Note:
1 <= tiles.length <= 7tilesconsists of uppercase English letters.
[Leetcode 1077] Project Employees III
原题说明
Table: Project
+————-+———+
| Column Name | Type |
+————-+———+
| project_id | int |
| employee_id | int |
+————-+———+
(project_id, employee_id) is the primary key of this table.
employee_id is a foreign key toEmployeetable.
Table: Employee
+——————+———+
| Column Name | Type |
+——————+———+
| employee_id | int |
| name | varchar |
| experience_years | int |
+——————+———+
employee_id is the primary key of this table.
Write an SQL query that reports the most experienced employees in each project. In case of a tie, report all employees with the maximum number of experience years.
The query result format is in the following example:
Project table:
+————-+————-+
| project_id | employee_id |
+————-+————-+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 4 |
+————-+————-+
Employee table:
+————-+——–+——————+
| employee_id | name | experience_years |
+————-+——–+——————+
| 1 | Khaled | 3 |
| 2 | Ali | 2 |
| 3 | John | 3 |
| 4 | Doe | 2 |
+————-+——–+——————+
Result table:
+————-+—————+
| project_id | employee_id |
+————-+—————+
| 1 | 1 |
| 1 | 3 |
| 2 | 1 |
+————-+—————+
Both employees with id 1 and 3 have the most experience among the employees of the first project. For the second project, the employee with id 1 has the most experience.
机械系PhD如何转行成为程序员
[Leetcode 1075] Project Employees I
原题说明
Table: Project
+————-+———+
| Column Name | Type |
+————-+———+
| project_id | int |
| employee_id | int |
+————-+———+
(project_id, employee_id) is the primary key of this table.
employee_id is a foreign key toEmployeetable.
Table: Employee
+——————+———+
| Column Name | Type |
+——————+———+
| employee_id | int |
| name | varchar |
| experience_years | int |
+——————+———+
employee_id is the primary key of this table.
Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.
The query result format is in the following example:
Project table:
+————-+————-+
| project_id | employee_id |
+————-+————-+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 4 |
+————-+————-+
Employee table:
+————-+——–+——————+
| employee_id | name | experience_years |
+————-+——–+——————+
| 1 | Khaled | 3 |
| 2 | Ali | 2 |
| 3 | John | 1 |
| 4 | Doe | 2 |
+————-+——–+——————+
Result table:
+————-+—————+
| project_id | average_years |
+————-+—————+
| 1 | 2.00 |
| 2 | 2.50 |
+————-+—————+
The average experience years for the first project is (3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50
[Leetcode 1073] Adding Two Negabinary Numbers
原题说明
Given two numbers arr1 and arr2 in base -2, return the result of adding them together.
Each number is given in array format: as an array of 0s and 1s, from most significant bit to least significant bit. For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3. A number arr in array format is also guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.
Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.
Example 1:
Input: arr1 = [1,1,1,1,1], arr2 = [1,0,1]
Output: [1,0,0,0,0]
Explanation: arr1 represents 11, arr2 represents 5, the output represents 16.
Note:
1 <= arr1.length <= 10001 <= arr2.length <= 1000arr1andarr2have no leading zerosarr1[i]is0or1arr2[i]is0or1





