From 01e0aa5c7787d154bc545cbe5dc5c4c6ad8a13ce Mon Sep 17 00:00:00 2001 From: Shuo Date: Fri, 6 Mar 2020 09:30:17 +0800 Subject: [PATCH 1/2] Add: new --- README.md | 20 ++-- problems/ads-performance/README.md | 2 +- .../README.md | 4 +- .../convert-bst-to-greater-tree/README.md | 7 +- problems/find-leaves-of-binary-tree/README.md | 2 +- .../README.md | 14 +++ .../mysql_schemas.sql | 6 ++ problems/height-checker/README.md | 25 ++++- .../README.md | 67 +++++++++++++ problems/largest-multiple-of-three/README.md | 2 +- problems/linked-list-in-binary-tree/README.md | 66 +++++++++++++ .../README.md | 2 +- problems/market-analysis-ii/README.md | 2 +- .../README.md | 91 ++++++++++++++++++ .../README.md | 2 +- .../README.md | 14 +++ .../mysql_schemas.sql | 22 +++++ .../product-of-array-except-self/README.md | 2 + problems/rank-teams-by-votes/README.md | 95 +++++++++++++++++++ .../README.md | 2 +- problems/remove-duplicate-letters/README.md | 2 + .../README.md | 2 + problems/restaurant-growth/README.md | 2 +- .../README.md | 2 +- .../README.md | 6 +- .../README.md | 2 +- problems/the-dining-philosophers/README.md | 6 +- readme/301-600.md | 2 +- tag/array/README.md | 2 + tag/breadth-first-search/README.md | 1 + tag/depth-first-search/README.md | 2 +- tag/dynamic-programming/README.md | 1 + tag/hash-table/README.md | 1 + tag/linked-list/README.md | 1 + tag/sort/README.md | 1 + tag/tree/README.md | 3 +- 36 files changed, 450 insertions(+), 33 deletions(-) create mode 100644 problems/get-the-second-most-recent-activity/README.md create mode 100644 problems/get-the-second-most-recent-activity/mysql_schemas.sql create mode 100644 problems/how-many-numbers-are-smaller-than-the-current-number/README.md create mode 100644 problems/linked-list-in-binary-tree/README.md create mode 100644 problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/README.md create mode 100644 problems/number-of-trusted-contacts-of-a-customer/README.md create mode 100644 problems/number-of-trusted-contacts-of-a-customer/mysql_schemas.sql create mode 100644 problems/rank-teams-by-votes/README.md diff --git a/README.md b/README.md index ee918bcdc..a0092daee 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,12 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1369 | [Get the Second Most Recent Activity](https://leetcode.com/problems/get-the-second-most-recent-activity) 🔒 | [MySQL](problems/get-the-second-most-recent-activity) | Hard | +| 1368 | [Minimum Cost to Make at Least One Valid Path in a Grid](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid "使网格图至少有一条有效路径的最小代价") | [Go](problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid) | Hard | +| 1367 | [Linked List in Binary Tree](https://leetcode.com/problems/linked-list-in-binary-tree "二叉树中的列表") | [Go](problems/linked-list-in-binary-tree) | Medium | +| 1366 | [Rank Teams by Votes](https://leetcode.com/problems/rank-teams-by-votes "通过投票对团队排名") | [Go](problems/rank-teams-by-votes) | Medium | +| 1365 | [How Many Numbers Are Smaller Than the Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number "有多少小于当前数字的数字") | [Go](problems/how-many-numbers-are-smaller-than-the-current-number) | Easy | +| 1364 | [Number of Trusted Contacts of a Customer](https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer "顾客的可信联系人数量") 🔒 | [MySQL](problems/number-of-trusted-contacts-of-a-customer) | Medium | | 1363 | [Largest Multiple of Three](https://leetcode.com/problems/largest-multiple-of-three "形成三的最大倍数") | [Go](problems/largest-multiple-of-three) | Hard | | 1362 | [Closest Divisors](https://leetcode.com/problems/closest-divisors "最接近的因数") | [Go](problems/closest-divisors) | Medium | | 1361 | [Validate Binary Tree Nodes](https://leetcode.com/problems/validate-binary-tree-nodes "验证二叉树") | [Go](problems/validate-binary-tree-nodes) | Medium | @@ -75,7 +81,7 @@ LeetCode Problems' Solutions | 1353 | [Maximum Number of Events That Can Be Attended](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended "最多可以参加的会议数目") | [Go](problems/maximum-number-of-events-that-can-be-attended) | Medium | | 1352 | [Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers "最后 K 个数的乘积") | [Go](problems/product-of-the-last-k-numbers) | Medium | | 1351 | [Count Negative Numbers in a Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix "统计有序矩阵中的负数") | [Go](problems/count-negative-numbers-in-a-sorted-matrix) | Easy | -| 1350 | [Students With Invalid Departments](https://leetcode.com/problems/students-with-invalid-departments) 🔒 | [MySQL](problems/students-with-invalid-departments) | Easy | +| 1350 | [Students With Invalid Departments](https://leetcode.com/problems/students-with-invalid-departments "院系无效的学生") 🔒 | [MySQL](problems/students-with-invalid-departments) | Easy | | 1349 | [Maximum Students Taking Exam](https://leetcode.com/problems/maximum-students-taking-exam "参加考试的最大学生数") | [Go](problems/maximum-students-taking-exam) | Hard | | 1348 | [Tweet Counts Per Frequency](https://leetcode.com/problems/tweet-counts-per-frequency "推文计数") | [Go](problems/tweet-counts-per-frequency) | Medium | | 1347 | [Minimum Number of Steps to Make Two Strings Anagram](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram "制造字母异位词的最小步骤数") | [Go](problems/minimum-number-of-steps-to-make-two-strings-anagram) | Medium | @@ -89,7 +95,7 @@ LeetCode Problems' Solutions | 1339 | [Maximum Product of Splitted Binary Tree](https://leetcode.com/problems/maximum-product-of-splitted-binary-tree "分裂二叉树的最大乘积") | [Go](problems/maximum-product-of-splitted-binary-tree) | Medium | | 1338 | [Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half "数组大小减半") | [Go](problems/reduce-array-size-to-the-half) | Medium | | 1337 | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix "方阵中战斗力最弱的 K 行") | [Go](problems/the-k-weakest-rows-in-a-matrix) | Easy | -| 1336 | [Number of Transactions per Visit](https://leetcode.com/problems/number-of-transactions-per-visit) 🔒 | [MySQL](problems/number-of-transactions-per-visit) | Hard | +| 1336 | [Number of Transactions per Visit](https://leetcode.com/problems/number-of-transactions-per-visit "每次访问的交易次数") 🔒 | [MySQL](problems/number-of-transactions-per-visit) | Hard | | 1335 | [Minimum Difficulty of a Job Schedule](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule "工作计划的最低难度") | [Go](problems/minimum-difficulty-of-a-job-schedule) | Hard | | 1334 | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance "阈值距离内邻居最少的城市") | [Go](problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance) | Medium | | 1333 | [Filter Restaurants by Vegan-Friendly, Price and Distance](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance "餐厅过滤器") | [Go](problems/filter-restaurants-by-vegan-friendly-price-and-distance) | Medium | @@ -98,13 +104,13 @@ LeetCode Problems' Solutions | 1330 | [Reverse Subarray To Maximize Array Value](https://leetcode.com/problems/reverse-subarray-to-maximize-array-value "翻转子数组得到最大的数组值") | [Go](problems/reverse-subarray-to-maximize-array-value) | Hard | | 1329 | [Sort the Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally "将矩阵按对角线排序") | [Go](problems/sort-the-matrix-diagonally) | Medium | | 1328 | [Break a Palindrome](https://leetcode.com/problems/break-a-palindrome "破坏回文串") | [Go](problems/break-a-palindrome) | Medium | -| 1327 | [List the Products Ordered in a Period](https://leetcode.com/problems/list-the-products-ordered-in-a-period) 🔒 | [MySQL](problems/list-the-products-ordered-in-a-period) | Easy | +| 1327 | [List the Products Ordered in a Period](https://leetcode.com/problems/list-the-products-ordered-in-a-period "列出指定时间段内所有的下单产品") 🔒 | [MySQL](problems/list-the-products-ordered-in-a-period) | Easy | | 1326 | [Minimum Number of Taps to Open to Water a Garden](https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden "灌溉花园的最少水龙头数目") | [Go](problems/minimum-number-of-taps-to-open-to-water-a-garden) | Hard | | 1325 | [Delete Leaves With a Given Value](https://leetcode.com/problems/delete-leaves-with-a-given-value "删除给定值的叶子节点") | [Go](problems/delete-leaves-with-a-given-value) | Medium | | 1324 | [Print Words Vertically](https://leetcode.com/problems/print-words-vertically "竖直打印单词") | [Go](problems/print-words-vertically) | Medium | | 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number "6 和 9 组成的最大数字") | [Go](problems/maximum-69-number) | Easy | -| 1322 | [Ads Performance](https://leetcode.com/problems/ads-performance) 🔒 | [MySQL](problems/ads-performance) | Easy | -| 1321 | [Restaurant Growth](https://leetcode.com/problems/restaurant-growth) 🔒 | [MySQL](problems/restaurant-growth) | Medium | +| 1322 | [Ads Performance](https://leetcode.com/problems/ads-performance "广告效果") 🔒 | [MySQL](problems/ads-performance) | Easy | +| 1321 | [Restaurant Growth](https://leetcode.com/problems/restaurant-growth "餐馆营业额变化增长") 🔒 | [MySQL](problems/restaurant-growth) | Medium | | 1320 | [Minimum Distance to Type a Word Using Two Fingers](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers "二指输入的的最小距离") | [Go](problems/minimum-distance-to-type-a-word-using-two-fingers) | Hard | | 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected "连通网络的操作次数") | [Go](problems/number-of-operations-to-make-network-connected) | Medium | | 1318 | [Minimum Flips to Make a OR b Equal to c](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c "或运算的最小翻转次数") | [Go](problems/minimum-flips-to-make-a-or-b-equal-to-c) | Medium | @@ -117,7 +123,7 @@ LeetCode Problems' Solutions | 1311 | [Get Watched Videos by Your Friends](https://leetcode.com/problems/get-watched-videos-by-your-friends "获取你好友已观看的视频") | [Go](problems/get-watched-videos-by-your-friends) | Medium | | 1310 | [XOR Queries of a Subarray](https://leetcode.com/problems/xor-queries-of-a-subarray "子数组异或查询") | [Go](problems/xor-queries-of-a-subarray) | Medium | | 1309 | [Decrypt String from Alphabet to Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping "解码字母到整数映射") | [Go](problems/decrypt-string-from-alphabet-to-integer-mapping) | Easy | -| 1308 | [Running Total for Different Genders](https://leetcode.com/problems/running-total-for-different-genders) 🔒 | [MySQL](problems/running-total-for-different-genders) | Medium | +| 1308 | [Running Total for Different Genders](https://leetcode.com/problems/running-total-for-different-genders "不同性别每日分数总计") 🔒 | [MySQL](problems/running-total-for-different-genders) | Medium | | 1307 | [Verbal Arithmetic Puzzle](https://leetcode.com/problems/verbal-arithmetic-puzzle "口算难题") | [Go](problems/verbal-arithmetic-puzzle) | Hard | | 1306 | [Jump Game III](https://leetcode.com/problems/jump-game-iii "跳跃游戏 III") | [Go](problems/jump-game-iii) | Medium | | 1305 | [All Elements in Two Binary Search Trees](https://leetcode.com/problems/all-elements-in-two-binary-search-trees "两棵二叉搜索树中的所有元素") | [Go](problems/all-elements-in-two-binary-search-trees) | Medium | @@ -266,7 +272,7 @@ LeetCode Problems' Solutions | 1162 | [As Far from Land as Possible](https://leetcode.com/problems/as-far-from-land-as-possible "地图分析") | [Go](problems/as-far-from-land-as-possible) | Medium | | 1161 | [Maximum Level Sum of a Binary Tree](https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree "最大层内元素和") | [Go](problems/maximum-level-sum-of-a-binary-tree) | Medium | | 1160 | [Find Words That Can Be Formed by Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters "拼写单词") | [Go](problems/find-words-that-can-be-formed-by-characters) | Easy | -| 1159 | [Market Analysis II](https://leetcode.com/problems/market-analysis-ii) 🔒 | [MySQL](problems/market-analysis-ii) | Hard | +| 1159 | [Market Analysis II](https://leetcode.com/problems/market-analysis-ii "市场分析 II") 🔒 | [MySQL](problems/market-analysis-ii) | Hard | | 1158 | [Market Analysis I](https://leetcode.com/problems/market-analysis-i "市场分析 I") 🔒 | [MySQL](problems/market-analysis-i) | Medium | | 1157 | [Online Majority Element In Subarray](https://leetcode.com/problems/online-majority-element-in-subarray "子数组中占绝大多数的元素") | [Go](problems/online-majority-element-in-subarray) | Hard | | 1156 | [Swap For Longest Repeated Character Substring](https://leetcode.com/problems/swap-for-longest-repeated-character-substring "单字符重复子串的最大长度") | [Go](problems/swap-for-longest-repeated-character-substring) | Medium | diff --git a/problems/ads-performance/README.md b/problems/ads-performance/README.md index 713d3a9a8..91befe0f6 100644 --- a/problems/ads-performance/README.md +++ b/problems/ads-performance/README.md @@ -9,7 +9,7 @@                  [Next >](../maximum-69-number "Maximum 69 Number") -## [1322. Ads Performance (Easy)](https://leetcode.com/problems/ads-performance "") +## [1322. Ads Performance (Easy)](https://leetcode.com/problems/ads-performance "广告效果")

Table: 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 @@
 

 

-

Note:

+

Constraints:

  1. The number of nodes in the tree is between 1 and 100.
  2. @@ -46,7 +46,7 @@
    -
     
    +
    Note: This question is the same as 538: https://leetcode.com/problems/convert-bst-to-greater-tree/
    diff --git a/problems/convert-bst-to-greater-tree/README.md b/problems/convert-bst-to-greater-tree/README.md index 4fcf2c680..29a9af0b8 100644 --- a/problems/convert-bst-to-greater-tree/README.md +++ b/problems/convert-bst-to-greater-tree/README.md @@ -13,8 +13,8 @@

    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:

    +
     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 each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[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
    • +
    + +### Related Topics + [[Array](../../tag/array/README.md)] + [[Hash Table](../../tag/hash-table/README.md)] + +### Hints +
    +Hint 1 +Brute force for each array element. +
    + +
    +Hint 2 +In order to improve the time complexity, we can sort the array and get the answer for each array element. +
    diff --git a/problems/largest-multiple-of-three/README.md b/problems/largest-multiple-of-three/README.md index c32499e8f..72e8b52e2 100644 --- a/problems/largest-multiple-of-three/README.md +++ b/problems/largest-multiple-of-three/README.md @@ -7,7 +7,7 @@ [< Previous](../closest-divisors "Closest Divisors")                  -Next > +[Next >](../number-of-trusted-contacts-of-a-customer "Number of Trusted Contacts of a Customer") ## [1363. Largest Multiple of Three (Hard)](https://leetcode.com/problems/largest-multiple-of-three "形成三的最大倍数") diff --git a/problems/linked-list-in-binary-tree/README.md b/problems/linked-list-in-binary-tree/README.md new file mode 100644 index 000000000..55de122a8 --- /dev/null +++ b/problems/linked-list-in-binary-tree/README.md @@ -0,0 +1,66 @@ + + + + + + + +[< Previous](../rank-teams-by-votes "Rank Teams by Votes") +                 +[Next >](../minimum-cost-to-make-at-least-one-valid-path-in-a-grid "Minimum Cost to Make at Least One Valid Path in a Grid") + +## [1367. Linked List in Binary Tree (Medium)](https://leetcode.com/problems/linked-list-in-binary-tree "二叉树中的列表") + +

    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.
    • +
    • The given linked list will contain between 1 and 100 nodes.
    • +
    • The given binary tree will contain between 1 and 2500 nodes.
    • +
    + +### Related Topics + [[Tree](../../tag/tree/README.md)] + [[Linked List](../../tag/linked-list/README.md)] + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
    +Hint 1 +Create recursive function, given a pointer in a Linked List and any node in the Binary Tree. Check if all the elements in the linked list starting from the head correspond to some downward path in the binary tree. +
    diff --git a/problems/list-the-products-ordered-in-a-period/README.md b/problems/list-the-products-ordered-in-a-period/README.md index acfd83aae..26471f8b5 100644 --- a/problems/list-the-products-ordered-in-a-period/README.md +++ b/problems/list-the-products-ordered-in-a-period/README.md @@ -9,7 +9,7 @@                  [Next >](../break-a-palindrome "Break a Palindrome") -## [1327. List the Products Ordered in a Period (Easy)](https://leetcode.com/problems/list-the-products-ordered-in-a-period "") +## [1327. List the Products Ordered in a Period (Easy)](https://leetcode.com/problems/list-the-products-ordered-in-a-period "列出指定时间段内所有的下单产品") SQL Schema

    Table: Products

    diff --git a/problems/market-analysis-ii/README.md b/problems/market-analysis-ii/README.md index 6638e8aa6..84e817704 100644 --- a/problems/market-analysis-ii/README.md +++ b/problems/market-analysis-ii/README.md @@ -9,7 +9,7 @@                  [Next >](../find-words-that-can-be-formed-by-characters "Find Words That Can Be Formed by Characters") -## [1159. Market Analysis II (Hard)](https://leetcode.com/problems/market-analysis-ii "") +## [1159. Market Analysis II (Hard)](https://leetcode.com/problems/market-analysis-ii "市场分析 II")

    Table: Users

    diff --git a/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/README.md b/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/README.md new file mode 100644 index 000000000..86f4c2a97 --- /dev/null +++ b/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/README.md @@ -0,0 +1,91 @@ + + + + + + + +[< Previous](../linked-list-in-binary-tree "Linked List in Binary Tree") +                 +[Next >](../get-the-second-most-recent-activity "Get the Second Most Recent Activity") + +## [1368. Minimum Cost to Make at Least One Valid Path in a Grid (Hard)](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid "使网格图至少有一条有效路径的最小代价") + +Given a m x n 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: +
      +
    • 1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])
    • +
    • 2 which means go to the cell to the left. (i.e go from grid[i][j] to grid[i][j - 1])
    • +
    • 3 which means go to the lower cell. (i.e go from grid[i][j] to grid[i + 1][j])
    • +
    • 4 which means go to the upper cell. (i.e go from 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
    • +
    + +### Related Topics + [[Breadth-first Search](../../tag/breadth-first-search/README.md)] + +### Hints +
    +Hint 1 +Build a graph where grid[i][j] is connected to all the four side-adjacent cells with weighted edge. the weight is 0 if the sign is pointing to the adjacent cell or 1 otherwise. +
    + +
    +Hint 2 +Do BFS from (0, 0) visit all edges with weight = 0 first. the answer is the distance to (m -1, n - 1). +
    diff --git a/problems/number-of-transactions-per-visit/README.md b/problems/number-of-transactions-per-visit/README.md index fce4ce6f3..61e8f63b9 100644 --- a/problems/number-of-transactions-per-visit/README.md +++ b/problems/number-of-transactions-per-visit/README.md @@ -9,7 +9,7 @@                  [Next >](../the-k-weakest-rows-in-a-matrix "The K Weakest Rows in a Matrix") -## [1336. Number of Transactions per Visit (Hard)](https://leetcode.com/problems/number-of-transactions-per-visit "") +## [1336. Number of Transactions per Visit (Hard)](https://leetcode.com/problems/number-of-transactions-per-visit "每次访问的交易次数")

    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.
    • +
    • All characters of votes[i] are unique.
    • +
    • All the characters that occur in votes[0] also occur in votes[j] where 1 <= j < votes.length.
    • +
    + +### Related Topics + [[Sort](../../tag/sort/README.md)] + [[Array](../../tag/array/README.md)] + +### Hints +
    +Hint 1 +Build array rank where rank[i][j] is the number of votes for team i to be the j-th rank. +
    + +
    +Hint 2 +Sort the trams by rank array. if rank array is the same for two or more teams, sort them by the ID in ascending order. +
    diff --git a/problems/rearrange-string-k-distance-apart/README.md b/problems/rearrange-string-k-distance-apart/README.md index 210352a9b..8ab0f8b6e 100644 --- a/problems/rearrange-string-k-distance-apart/README.md +++ b/problems/rearrange-string-k-distance-apart/README.md @@ -43,9 +43,9 @@
    ### Related Topics - [[Hash Table](../../tag/hash-table/README.md)] [[Heap](../../tag/heap/README.md)] [[Greedy](../../tag/greedy/README.md)] + [[Hash Table](../../tag/hash-table/README.md)] ### Similar Questions 1. [Task Scheduler](../task-scheduler) (Medium) diff --git a/problems/remove-duplicate-letters/README.md b/problems/remove-duplicate-letters/README.md index 7de020501..996d871f6 100644 --- a/problems/remove-duplicate-letters/README.md +++ b/problems/remove-duplicate-letters/README.md @@ -27,6 +27,8 @@ Output: "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 of text exactly once.

-

 

-

Example 1:

@@ -48,14 +46,14 @@
 
 

 

-

Note:

+

Constraints:

  1. 1 <= text.length <= 1000
  2. 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.
  • The philosophers are assumed to be thinking as long as they are not asking to eat (the function is not being called with their number).
  • -

    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: Shuo Date: Fri, 6 Mar 2020 09:37:51 +0800 Subject: [PATCH 2/2] Add: desc --- problems/activity-participants/README.md | 64 +++++++++++++ problems/movie-rating/README.md | 92 +++++++++++++++++++ .../README.md | 67 ++++++++++++++ 3 files changed, 223 insertions(+) diff --git a/problems/activity-participants/README.md b/problems/activity-participants/README.md index 47c6a14fb..3531f2acc 100644 --- a/problems/activity-participants/README.md +++ b/problems/activity-participants/README.md @@ -11,4 +11,68 @@ ## [1355. Activity Participants (Medium)](https://leetcode.com/problems/activity-participants "") +

    Table: 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.
    +