From 01e0aa5c7787d154bc545cbe5dc5c4c6ad8a13ce Mon Sep 17 00:00:00 2001
From: Shuo Table: Note: Constraints: Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.
-Example:
+ Example:Ads
diff --git a/problems/binary-search-tree-to-greater-sum-tree/README.md b/problems/binary-search-tree-to-greater-sum-tree/README.md
index 513955281..873ca95a4 100644
--- a/problems/binary-search-tree-to-greater-sum-tree/README.md
+++ b/problems/binary-search-tree-to-greater-sum-tree/README.md
@@ -36,7 +36,7 @@
1
and 100
.
Input: The root of a Binary Search Tree like this:
5
@@ -26,7 +26,8 @@
/ \
20 13
-
Note: This question is the same as 1038: https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/
### Related Topics [[Tree](../../tag/tree/README.md)] diff --git a/problems/find-leaves-of-binary-tree/README.md b/problems/find-leaves-of-binary-tree/README.md index 6c0bda5a5..a60428896 100644 --- a/problems/find-leaves-of-binary-tree/README.md +++ b/problems/find-leaves-of-binary-tree/README.md @@ -9,7 +9,7 @@ [Next >](../valid-perfect-square "Valid Perfect Square") -## [366. Find Leaves of Binary Tree (Medium)](https://leetcode.com/problems/find-leaves-of-binary-tree "寻找完全二叉树的叶子节点") +## [366. Find Leaves of Binary Tree (Medium)](https://leetcode.com/problems/find-leaves-of-binary-tree "寻找二叉树的叶子节点")Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves, repeat until the tree is empty.
diff --git a/problems/get-the-second-most-recent-activity/README.md b/problems/get-the-second-most-recent-activity/README.md new file mode 100644 index 000000000..4953f59b4 --- /dev/null +++ b/problems/get-the-second-most-recent-activity/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](../minimum-cost-to-make-at-least-one-valid-path-in-a-grid "Minimum Cost to Make at Least One Valid Path in a Grid") + +Next > + +## [1369. Get the Second Most Recent Activity (Hard)](https://leetcode.com/problems/get-the-second-most-recent-activity "") + + diff --git a/problems/get-the-second-most-recent-activity/mysql_schemas.sql b/problems/get-the-second-most-recent-activity/mysql_schemas.sql new file mode 100644 index 000000000..880eded3e --- /dev/null +++ b/problems/get-the-second-most-recent-activity/mysql_schemas.sql @@ -0,0 +1,6 @@ +Create table If Not Exists UserActivity (username varchar(30), activity varchar(30), startDate date, endDate date); +Truncate table UserActivity; +insert into UserActivity (username, activity, startDate, endDate) values ('Alice', 'Travel', '2020-02-12', '2020-02-20'); +insert into UserActivity (username, activity, startDate, endDate) values ('Alice', 'Dancing', '2020-02-21', '2020-02-23'); +insert into UserActivity (username, activity, startDate, endDate) values ('Alice', 'Travel', '2020-02-24', '2020-02-28'); +insert into UserActivity (username, activity, startDate, endDate) values ('Bob', 'Travel', '2020-02-11', '2020-02-18'); diff --git a/problems/height-checker/README.md b/problems/height-checker/README.md index 440eb14b1..13b28d7d4 100644 --- a/problems/height-checker/README.md +++ b/problems/height-checker/README.md @@ -17,9 +17,32 @@
Example 1:
-Input: heights = [1,1,4,2,1,3] + ++Input: heights = [1,1,4,2,1,3] Output: 3 +Explanation: +Current array : [1,1,4,2,1,3] +Target array : [1,1,1,2,3,4] +On index 2 (0-based) we have 4 vs 1 so we have to move this student. +On index 4 (0-based) we have 1 vs 3 so we have to move this student. +On index 5 (0-based) we have 3 vs 4 so we have to move this student. ++ +Example 2:
+ ++Input: heights = [5,1,2,3,4] +Output: 5+ +Example 3:
+ ++Input: heights = [1,2,3,4,5] +Output: 0 ++
Constraints:
diff --git a/problems/how-many-numbers-are-smaller-than-the-current-number/README.md b/problems/how-many-numbers-are-smaller-than-the-current-number/README.md new file mode 100644 index 000000000..9f8056258 --- /dev/null +++ b/problems/how-many-numbers-are-smaller-than-the-current-number/README.md @@ -0,0 +1,67 @@ + + + + + + + +[< Previous](../number-of-trusted-contacts-of-a-customer "Number of Trusted Contacts of a Customer") + +[Next >](../rank-teams-by-votes "Rank Teams by Votes") + +## [1365. How Many Numbers Are Smaller Than the Current Number (Easy)](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number "有多少小于当前数字的数字") + +Given the array
+ +nums
, for eachnums[i]
find out how many numbers in the array are smaller than it. That is, for eachnums[i]
you have to count the number of validj's
such thatj != i
andnums[j] < nums[i]
.Return the answer in an array.
+ ++
Example 1:
+ ++Input: nums = [8,1,2,2,3] +Output: [4,0,1,1,3] +Explanation: +For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). +For nums[1]=1 does not exist any smaller number than it. +For nums[2]=2 there exist one smaller number than it (1). +For nums[3]=2 there exist one smaller number than it (1). +For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2). ++ +Example 2:
+ ++Input: nums = [6,5,4,8] +Output: [2,1,0,3] ++ +Example 3:
+ ++Input: nums = [7,7,7,7] +Output: [0,0,0,0] ++ ++
Constraints:
+ +
2 <= nums.length <= 500
0 <= nums[i] <= 100
Given a binary tree root
and a linked list with head
as the first node.
Return True if all the elements in the linked list starting from the head
correspond to some downward path connected in the binary tree otherwise return False.
In this context downward path means a path that starts at some node and goes downwards.
+ ++
Example 1:
+ ++Input: head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3] +Output: true +Explanation: Nodes in blue form a subpath in the binary Tree. ++ +
Example 2:
+ ++Input: head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3] +Output: true ++ +
Example 3:
+ +
+Input: head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
+Output: false
+Explanation: There is no path in the binary tree that contains all the elements of the linked list from head
.
+
+
++
Constraints:
+ +1 <= node.val <= 100
for each node in the linked list and binary tree.1
and 100
nodes.1
and 2500
nodes.Table: Products
Table: Users
grid
. Each cell of the grid
has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j]
can be:
+grid[i][j]
to grid[i][j + 1]
)grid[i][j]
to grid[i][j - 1]
)grid[i][j]
to grid[i + 1][j]
)grid[i][j]
to grid[i - 1][j]
)Notice that there could be some invalid signs on the cells of the grid
which points outside the grid
.
You will initially start at the upper left cell (0,0)
. A valid path in the grid is a path which starts from the upper left cell (0,0)
and ends at the bottom-right cell (m - 1, n - 1)
following the signs on the grid. The valid path doesn't have to be the shortest.
You can modify the sign on a cell with cost = 1
. You can modify the sign on a cell one time only.
Return the minimum cost to make the grid have at least one valid path.
+ ++
Example 1:
++Input: grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]] +Output: 3 +Explanation: You will start at point (0, 0). +The path to (3, 3) is as follows. (0, 0) --> (0, 1) --> (0, 2) --> (0, 3) change the arrow to down with cost = 1 --> (1, 3) --> (1, 2) --> (1, 1) --> (1, 0) change the arrow to down with cost = 1 --> (2, 0) --> (2, 1) --> (2, 2) --> (2, 3) change the arrow to down with cost = 1 --> (3, 3) +The total cost = 3. ++ +
Example 2:
++Input: grid = [[1,1,3],[3,2,2],[1,1,4]] +Output: 0 +Explanation: You can follow the path from (0, 0) to (2, 2). ++ +
Example 3:
++Input: grid = [[1,2],[4,3]] +Output: 1 ++ +
Example 4:
+ ++Input: grid = [[2,2,2],[2,2,2]] +Output: 3 ++ +
Example 5:
+ ++Input: grid = [[4]] +Output: 0 ++ +
+
Constraints:
+ +m == grid.length
n == grid[i].length
1 <= m, n <= 100
Table: Visits
diff --git a/problems/number-of-trusted-contacts-of-a-customer/README.md b/problems/number-of-trusted-contacts-of-a-customer/README.md
new file mode 100644
index 000000000..1408b9119
--- /dev/null
+++ b/problems/number-of-trusted-contacts-of-a-customer/README.md
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+[< Previous](../largest-multiple-of-three "Largest Multiple of Three")
+
+[Next >](../how-many-numbers-are-smaller-than-the-current-number "How Many Numbers Are Smaller Than the Current Number")
+
+## [1364. Number of Trusted Contacts of a Customer (Medium)](https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer "顾客的可信联系人数量")
+
+
diff --git a/problems/number-of-trusted-contacts-of-a-customer/mysql_schemas.sql b/problems/number-of-trusted-contacts-of-a-customer/mysql_schemas.sql
new file mode 100644
index 000000000..608197d7b
--- /dev/null
+++ b/problems/number-of-trusted-contacts-of-a-customer/mysql_schemas.sql
@@ -0,0 +1,22 @@
+Create table If Not Exists Customers (customer_id int, customer_name varchar(20), email varchar(30));
+Create table If Not Exists Contacts (user_id int, contact_name varchar(20), contact_email varchar(30));
+Create table If Not Exists Invoices (invoice_id int, price int, user_id int);
+Truncate table Customers;
+insert into Customers (customer_id, customer_name, email) values ('1', 'Alice', 'alice@leetcode.com');
+insert into Customers (customer_id, customer_name, email) values ('2', 'Bob', 'bob@leetcode.com');
+insert into Customers (customer_id, customer_name, email) values ('13', 'John', 'john@leetcode.com');
+insert into Customers (customer_id, customer_name, email) values ('6', 'Alex', 'alex@leetcode.com');
+Truncate table Contacts;
+insert into Contacts (user_id, contact_name, contact_email) values ('1', 'Bob', 'bob@leetcode.com');
+insert into Contacts (user_id, contact_name, contact_email) values ('1', 'John', 'john@leetcode.com');
+insert into Contacts (user_id, contact_name, contact_email) values ('1', 'Jal', 'jal@leetcode.com');
+insert into Contacts (user_id, contact_name, contact_email) values ('2', 'Omar', 'omar@leetcode.com');
+insert into Contacts (user_id, contact_name, contact_email) values ('2', 'Meir', 'meir@leetcode.com');
+insert into Contacts (user_id, contact_name, contact_email) values ('6', 'Alice', 'alice@leetcode.com');
+Truncate table Invoices;
+insert into Invoices (invoice_id, price, user_id) values ('77', '100', '1');
+insert into Invoices (invoice_id, price, user_id) values ('88', '200', '1');
+insert into Invoices (invoice_id, price, user_id) values ('99', '300', '2');
+insert into Invoices (invoice_id, price, user_id) values ('66', '400', '2');
+insert into Invoices (invoice_id, price, user_id) values ('55', '500', '13');
+insert into Invoices (invoice_id, price, user_id) values ('44', '60', '6');
diff --git a/problems/product-of-array-except-self/README.md b/problems/product-of-array-except-self/README.md
index bdf68599c..b542b1fec 100644
--- a/problems/product-of-array-except-self/README.md
+++ b/problems/product-of-array-except-self/README.md
@@ -20,6 +20,8 @@
Output: [24,12,8,6]
+Constraint: It's guaranteed that the product of the elements of any preffix or suffix of the array (including the whole array) fits in a 32 bit integer.
+Note: Please solve it without division and in O(n).
Follow up:
diff --git a/problems/rank-teams-by-votes/README.md b/problems/rank-teams-by-votes/README.md
new file mode 100644
index 000000000..f041f7c56
--- /dev/null
+++ b/problems/rank-teams-by-votes/README.md
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+[< Previous](../how-many-numbers-are-smaller-than-the-current-number "How Many Numbers Are Smaller Than the Current Number")
+
+[Next >](../linked-list-in-binary-tree "Linked List in Binary Tree")
+
+## [1366. Rank Teams by Votes (Medium)](https://leetcode.com/problems/rank-teams-by-votes "通过投票对团队排名")
+
+
In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition.
+ +The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.
+ +Given an array of strings votes
which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.
Return a string of all teams sorted by the ranking system.
+ ++
Example 1:
+ ++Input: votes = ["ABC","ACB","ABC","ACB","ACB"] +Output: "ACB" +Explanation: Team A was ranked first place by 5 voters. No other team was voted as first place so team A is the first team. +Team B was ranked second by 2 voters and was ranked third by 3 voters. +Team C was ranked second by 3 voters and was ranked third by 2 voters. +As most of the voters ranked C second, team C is the second team and team B is the third. ++ +
Example 2:
+ ++Input: votes = ["WXYZ","XYZW"] +Output: "XWYZ" +Explanation: X is the winner due to tie-breaking rule. X has same votes as W for the first position but X has one vote as second position while W doesn't have any votes as second position. ++ +
Example 3:
+ ++Input: votes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"] +Output: "ZMNAGUEDSJYLBOPHRQICWFXTVK" +Explanation: Only one voter so his votes are used for the ranking. ++ +
Example 4:
+ ++Input: votes = ["BCA","CAB","CBA","ABC","ACB","BAC"] +Output: "ABC" +Explanation: +Team A was ranked first by 2 voters, second by 2 voters and third by 2 voters. +Team B was ranked first by 2 voters, second by 2 voters and third by 2 voters. +Team C was ranked first by 2 voters, second by 2 voters and third by 2 voters. +There is a tie and we rank teams ascending by their IDs. ++ +
Example 5:
+ ++Input: votes = ["M","M","M","M"] +Output: "M" +Explanation: Only team M in the competition so it has the first rank. ++ +
+
Constraints:
+ +1 <= votes.length <= 1000
1 <= votes[i].length <= 26
votes[i].length == votes[j].length
for 0 <= i, j < votes.length
.votes[i][j]
is an English upper-case letter.votes[i]
are unique.votes[0]
also occur in votes[j]
where 1 <= j < votes.length
."acdb"
+Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/
+ ### Related Topics [[Stack](../../tag/stack/README.md)] [[Greedy](../../tag/greedy/README.md)] diff --git a/problems/remove-duplicates-from-sorted-list-ii/README.md b/problems/remove-duplicates-from-sorted-list-ii/README.md index ec0ae0b3f..a59209fb5 100644 --- a/problems/remove-duplicates-from-sorted-list-ii/README.md +++ b/problems/remove-duplicates-from-sorted-list-ii/README.md @@ -13,6 +13,8 @@Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
+Return the linked list sorted as well.
+Example 1:
diff --git a/problems/restaurant-growth/README.md b/problems/restaurant-growth/README.md index 71b2ba3fb..4f767373e 100644 --- a/problems/restaurant-growth/README.md +++ b/problems/restaurant-growth/README.md @@ -9,7 +9,7 @@ [Next >](../ads-performance "Ads Performance") -## [1321. Restaurant Growth (Medium)](https://leetcode.com/problems/restaurant-growth "") +## [1321. Restaurant Growth (Medium)](https://leetcode.com/problems/restaurant-growth "餐馆营业额变化增长")Table:
Customer
diff --git a/problems/running-total-for-different-genders/README.md b/problems/running-total-for-different-genders/README.md index 3c975341e..9d0db8e7d 100644 --- a/problems/running-total-for-different-genders/README.md +++ b/problems/running-total-for-different-genders/README.md @@ -9,7 +9,7 @@ [Next >](../decrypt-string-from-alphabet-to-integer-mapping "Decrypt String from Alphabet to Integer Mapping") -## [1308. Running Total for Different Genders (Medium)](https://leetcode.com/problems/running-total-for-different-genders "") +## [1308. Running Total for Different Genders (Medium)](https://leetcode.com/problems/running-total-for-different-genders "不同性别每日分数总计")Table:
Scores
diff --git a/problems/smallest-subsequence-of-distinct-characters/README.md b/problems/smallest-subsequence-of-distinct-characters/README.md index c0a2b13e1..51438c964 100644 --- a/problems/smallest-subsequence-of-distinct-characters/README.md +++ b/problems/smallest-subsequence-of-distinct-characters/README.md @@ -13,8 +13,6 @@Return the lexicographically smallest subsequence of
-text
that contains all the distinct characters oftext
exactly once.-
Example 1:
@@ -48,14 +46,14 @@-
Note:
+Constraints:
-
1 <= text.length <= 1000
text
consists of lowercase English letters.+
Note: This question is the same as 316: https://leetcode.com/problems/remove-duplicate-letters/
diff --git a/problems/students-with-invalid-departments/README.md b/problems/students-with-invalid-departments/README.md index 2a1b9c1ec..1810f84f6 100644 --- a/problems/students-with-invalid-departments/README.md +++ b/problems/students-with-invalid-departments/README.md @@ -9,6 +9,6 @@ [Next >](../count-negative-numbers-in-a-sorted-matrix "Count Negative Numbers in a Sorted Matrix") -## [1350. Students With Invalid Departments (Easy)](https://leetcode.com/problems/students-with-invalid-departments "") +## [1350. Students With Invalid Departments (Easy)](https://leetcode.com/problems/students-with-invalid-departments "院系无效的学生") diff --git a/problems/the-dining-philosophers/README.md b/problems/the-dining-philosophers/README.md index c3718c5ca..297fcfa94 100644 --- a/problems/the-dining-philosophers/README.md +++ b/problems/the-dining-philosophers/README.md @@ -17,7 +17,7 @@Eating is not limited by the remaining amounts of spaghetti or stomach space; an infinite supply and an infinite demand are assumed.
-Design a discipline of behavior (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.
+Design a discipline of behaviour (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.
@@ -31,11 +31,11 @@
philosopher
is the id of the philosopher who wants to eat.pickLeftFork
and pickRightFork
are functions you can call to pick the corresponding forks of that philosopher.eat
is a function you can call to let the philosopher eat once he has picked both forks.putLeftFork
and pickRightFork
are functions you can call to put down the corresponding forks of that philosopher.putLeftFork
and putRightFork
are functions you can call to put down the corresponding forks of that philosopher.Five threads, each representing a philosopher, will simultaneously use one object of your class to simulate the process. It is possible that the function will be called for the same philosopher more than once, even before the last call ends.
+Five threads, each representing a philosopher, will simultaneously use one object of your class to simulate the process. The function may be called for the same philosopher more than once, even before the last call ends.
Example 1:
diff --git a/readme/301-600.md b/readme/301-600.md index 114f9523c..5d37d4931 100644 --- a/readme/301-600.md +++ b/readme/301-600.md @@ -127,7 +127,7 @@ LeetCode Problems' Solutions | 363 | [Max Sum of Rectangle No Larger Than K](https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k "矩形区域不超过 K 的最大数值和") | [Go](../problems/max-sum-of-rectangle-no-larger-than-k) | Hard | | 364 | [Nested List Weight Sum II](https://leetcode.com/problems/nested-list-weight-sum-ii "加权嵌套序列和 II") 🔒 | [Go](../problems/nested-list-weight-sum-ii) | Medium | | 365 | [Water and Jug Problem](https://leetcode.com/problems/water-and-jug-problem "水壶问题") | [Go](../problems/water-and-jug-problem) | Medium | -| 366 | [Find Leaves of Binary Tree](https://leetcode.com/problems/find-leaves-of-binary-tree "寻找完全二叉树的叶子节点") 🔒 | [Go](../problems/find-leaves-of-binary-tree) | Medium | +| 366 | [Find Leaves of Binary Tree](https://leetcode.com/problems/find-leaves-of-binary-tree "寻找二叉树的叶子节点") 🔒 | [Go](../problems/find-leaves-of-binary-tree) | Medium | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square "有效的完全平方数") | [Go](../problems/valid-perfect-square) | Easy | | 368 | [Largest Divisible Subset](https://leetcode.com/problems/largest-divisible-subset "最大整除子集") | [Go](../problems/largest-divisible-subset) | Medium | | 369 | [Plus One Linked List](https://leetcode.com/problems/plus-one-linked-list "给单链表加一") 🔒 | [Go](../problems/plus-one-linked-list) | Medium | diff --git a/tag/array/README.md b/tag/array/README.md index ba5742da3..286f15cb6 100644 --- a/tag/array/README.md +++ b/tag/array/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1366 | [通过投票对团队排名](../../problems/rank-teams-by-votes) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | +| 1365 | [有多少小于当前数字的数字](../../problems/how-many-numbers-are-smaller-than-the-current-number) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Easy | | 1352 | [最后 K 个数的乘积](../../problems/product-of-the-last-k-numbers) | [[设计](../design/README.md)] [[数组](../array/README.md)] | Medium | | 1351 | [统计有序矩阵中的负数](../../problems/count-negative-numbers-in-a-sorted-matrix) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Easy | | 1346 | [检查整数及其两倍数是否存在](../../problems/check-if-n-and-its-double-exist) | [[数组](../array/README.md)] | Easy | diff --git a/tag/breadth-first-search/README.md b/tag/breadth-first-search/README.md index 3b09315e2..90f4defa8 100644 --- a/tag/breadth-first-search/README.md +++ b/tag/breadth-first-search/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1368 | [使网格图至少有一条有效路径的最小代价](../../problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 1345 | [跳跃游戏 IV](../../problems/jump-game-iv) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 1319 | [连通网络的操作次数](../../problems/number-of-operations-to-make-network-connected) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | | 1311 | [获取你好友已观看的视频](../../problems/get-watched-videos-by-your-friends) | [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Medium | diff --git a/tag/depth-first-search/README.md b/tag/depth-first-search/README.md index ccbe74420..c694a5c87 100644 --- a/tag/depth-first-search/README.md +++ b/tag/depth-first-search/README.md @@ -92,7 +92,7 @@ | 430 | [扁平化多级双向链表](../../problems/flatten-a-multilevel-doubly-linked-list) | [[深度优先搜索](../depth-first-search/README.md)] [[链表](../linked-list/README.md)] | Medium | | 417 | [太平洋大西洋水流问题](../../problems/pacific-atlantic-water-flow) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | | 394 | [字符串解码](../../problems/decode-string) | [[栈](../stack/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | -| 366 | [寻找完全二叉树的叶子节点](../../problems/find-leaves-of-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | +| 366 | [寻找二叉树的叶子节点](../../problems/find-leaves-of-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 364 | [加权嵌套序列和 II](../../problems/nested-list-weight-sum-ii) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 339 | [嵌套列表权重和](../../problems/nested-list-weight-sum) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] | Easy | | 337 | [打家劫舍 III](../../problems/house-robber-iii) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | diff --git a/tag/dynamic-programming/README.md b/tag/dynamic-programming/README.md index e9291e5a1..117dc00e3 100644 --- a/tag/dynamic-programming/README.md +++ b/tag/dynamic-programming/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1367 | [二叉树中的列表](../../problems/linked-list-in-binary-tree) | [[树](../tree/README.md)] [[链表](../linked-list/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1363 | [形成三的最大倍数](../../problems/largest-multiple-of-three) | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1359 | [有效的快递序列数目](../../problems/count-all-valid-pickup-and-delivery-options) | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1349 | [参加考试的最大学生数](../../problems/maximum-students-taking-exam) | [[动态规划](../dynamic-programming/README.md)] | Hard | diff --git a/tag/hash-table/README.md b/tag/hash-table/README.md index 6aa1733f9..f64eb2adf 100644 --- a/tag/hash-table/README.md +++ b/tag/hash-table/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1365 | [有多少小于当前数字的数字](../../problems/how-many-numbers-are-smaller-than-the-current-number) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Easy | | 1311 | [获取你好友已观看的视频](../../problems/get-watched-videos-by-your-friends) | [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Medium | | 1261 | [在受污染的二叉树中查找元素](../../problems/find-elements-in-a-contaminated-binary-tree) | [[树](../tree/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1244 | [力扣排行榜](../../problems/design-a-leaderboard) 🔒 | [[排序](../sort/README.md)] [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Medium | diff --git a/tag/linked-list/README.md b/tag/linked-list/README.md index d186d7105..2d5a361ce 100644 --- a/tag/linked-list/README.md +++ b/tag/linked-list/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1367 | [二叉树中的列表](../../problems/linked-list-in-binary-tree) | [[树](../tree/README.md)] [[链表](../linked-list/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1290 | [二进制链表转整数](../../problems/convert-binary-number-in-a-linked-list-to-integer) | [[位运算](../bit-manipulation/README.md)] [[链表](../linked-list/README.md)] | Easy | | 1171 | [从链表中删去总和值为零的连续节点](../../problems/remove-zero-sum-consecutive-nodes-from-linked-list) | [[链表](../linked-list/README.md)] | Medium | | 1019 | [链表中的下一个更大节点](../../problems/next-greater-node-in-linked-list) | [[栈](../stack/README.md)] [[链表](../linked-list/README.md)] | Medium | diff --git a/tag/sort/README.md b/tag/sort/README.md index 6880ce48e..247a8caef 100644 --- a/tag/sort/README.md +++ b/tag/sort/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1366 | [通过投票对团队排名](../../problems/rank-teams-by-votes) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | | 1356 | [根据数字二进制下 1 的数目排序](../../problems/sort-integers-by-the-number-of-1-bits) | [[排序](../sort/README.md)] [[位运算](../bit-manipulation/README.md)] | Easy | | 1353 | [最多可以参加的会议数目](../../problems/maximum-number-of-events-that-can-be-attended) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] [[线段树](../segment-tree/README.md)] | Medium | | 1333 | [餐厅过滤器](../../problems/filter-restaurants-by-vegan-friendly-price-and-distance) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | diff --git a/tag/tree/README.md b/tag/tree/README.md index 78d48cd39..a7053ac1d 100644 --- a/tag/tree/README.md +++ b/tag/tree/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1367 | [二叉树中的列表](../../problems/linked-list-in-binary-tree) | [[树](../tree/README.md)] [[链表](../linked-list/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1339 | [分裂二叉树的最大乘积](../../problems/maximum-product-of-splitted-binary-tree) | [[树](../tree/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1325 | [删除给定值的叶子节点](../../problems/delete-leaves-with-a-given-value) | [[树](../tree/README.md)] | Medium | | 1315 | [祖父节点值为偶数的节点和](../../problems/sum-of-nodes-with-even-valued-grandparent) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | @@ -93,7 +94,7 @@ | 428 | [序列化和反序列化 N 叉树](../../problems/serialize-and-deserialize-n-ary-tree) 🔒 | [[树](../tree/README.md)] | Hard | | 426 | [将二叉搜索树转化为排序的双向链表](../../problems/convert-binary-search-tree-to-sorted-doubly-linked-list) 🔒 | [[树](../tree/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Medium | | 404 | [左叶子之和](../../problems/sum-of-left-leaves) | [[树](../tree/README.md)] | Easy | -| 366 | [寻找完全二叉树的叶子节点](../../problems/find-leaves-of-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | +| 366 | [寻找二叉树的叶子节点](../../problems/find-leaves-of-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 337 | [打家劫舍 III](../../problems/house-robber-iii) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 333 | [最大 BST 子树](../../problems/largest-bst-subtree) 🔒 | [[树](../tree/README.md)] | Medium | | 298 | [二叉树最长连续序列](../../problems/binary-tree-longest-consecutive-sequence) 🔒 | [[树](../tree/README.md)] | Medium | From 23e5bc8abe3888d4b56d12a98a310c217620c50c Mon Sep 17 00:00:00 2001 From: ShuoTable: Friends
++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| id | int | +| name | varchar | +| activity | varchar | ++---------------+---------+ +id is the id of the friend and primary key for this table. +name is the name of the friend. +activity is the name of the activity which the friend takes part in. ++
Table: Activities
++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| id | int | +| name | varchar | ++---------------+---------+ +id is the primary key for this table. +name is the name of the activity. ++ +Write an SQL query to find the names of all the activities with neither maximum, nor minimum number of participants. + +Return the result table in any order. Each activity in table Activities is performed by any person in the table Friends. + +The query result format is in the following example: + +Friends table: +
++------+--------------+---------------+ +| id | name | activity | ++------+--------------+---------------+ +| 1 | Jonathan D. | Eating | +| 2 | Jade W. | Singing | +| 3 | Victor J. | Singing | +| 4 | Elvis Q. | Eating | +| 5 | Daniel A. | Eating | +| 6 | Bob B. | Horse Riding | ++------+--------------+---------------+ + +Activities table: ++------+--------------+ +| id | name | ++------+--------------+ +| 1 | Eating | +| 2 | Singing | +| 3 | Horse Riding | ++------+--------------+ + +Result table: ++--------------+ +| results | ++--------------+ +| Singing | ++--------------+ + +Eating activity is performed by 3 friends, maximum number of participants, (Jonathan D. , Elvis Q. and Daniel A.) +Horse Riding activity is performed by 1 friend, minimum number of participants, (Bob B.) +Singing is performed by 2 friends (Victor J. and Jade W.) +diff --git a/problems/movie-rating/README.md b/problems/movie-rating/README.md index 7d825c727..6f65cba68 100644 --- a/problems/movie-rating/README.md +++ b/problems/movie-rating/README.md @@ -11,4 +11,96 @@ ## [1341. Movie Rating (Medium)](https://leetcode.com/problems/movie-rating "电影评分") +
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: Movie_Rating
++---------------+---------+ +| 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 the following SQL query: + +- Find the name of the user who has rated the greatest number of the movies. + In case of a tie, return lexicographically smaller user name. + +- Find the movie name with the highest average rating as of Feb 2020. + In case of a tie, return lexicographically smaller movie name.. + +Query is returned in 2 rows, the query result format is in the folowing example: +
+Movie table: ++-------------+--------------+ +| movie_id | title | ++-------------+--------------+ +| 1 | Avengers | +| 2 | Frozen 2 | +| 3 | Joker | ++-------------+--------------+ + +Users table: ++-------------+--------------+ +| user_id | name | ++-------------+--------------+ +| 1 | Daniel | +| 2 | Monica | +| 3 | Maria | +| 4 | James | ++-------------+--------------+ + +Movie_Rating 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 | ++-------------+--------------+--------------+-------------+ + +Result table: ++--------------+ +| results | ++--------------+ +| Daniel | +| Frozen 2 | ++--------------+ + +Daniel and Maria 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/problems/students-with-invalid-departments/README.md b/problems/students-with-invalid-departments/README.md index 1810f84f6..b696a87a5 100644 --- a/problems/students-with-invalid-departments/README.md +++ b/problems/students-with-invalid-departments/README.md @@ -11,4 +11,71 @@ ## [1350. Students With Invalid Departments (Easy)](https://leetcode.com/problems/students-with-invalid-departments "院系无效的学生") +
Table: Departments
++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| id | int | +| name | varchar | ++---------------+---------+ +id is the primary key of this table. +The table has information about the id of each department of a university. ++ +
Table: Students
++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| id | int | +| name | varchar | +| department_id | int | ++---------------+---------+ +id is the primary key of this table. +The table has information about the id of each student at a university and the id of the department he/she studies at. ++ +Write an SQL query to find the id and the name of all students who are enrolled in departments that no longer exists. +Return the result table in any order. + +The query result format is in the following example: +
+Departments table: ++------+--------------------------+ +| id | name | ++------+--------------------------+ +| 1 | Electrical Engineering | +| 7 | Computer Engineering | +| 13 | Bussiness Administration | ++------+--------------------------+ + +Students table: ++------+----------+---------------+ +| id | name | department_id | ++------+----------+---------------+ +| 23 | Alice | 1 | +| 1 | Bob | 7 | +| 5 | Jennifer | 13 | +| 2 | John | 14 | +| 4 | Jasmine | 77 | +| 3 | Steve | 74 | +| 6 | Luis | 1 | +| 8 | Jonathan | 7 | +| 7 | Daiana | 33 | +| 11 | Madelynn | 1 | ++------+----------+---------------+ + +Result table: ++------+----------+ +| id | name | ++------+----------+ +| 2 | John | +| 7 | Daiana | +| 4 | Jasmine | +| 3 | Steve | ++------+----------+ + +John, Daiana, Steve and Jasmine are enrolled in departments 14, 33, 74 and 77 respectively. department 14, 33, 74 and 77 doesn't exist in the Departments table. +