diff --git a/README.md b/README.md index c9d692777..6fd0cfc70 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1163 | [Last Substring in Lexicographical Order](https://leetcode.com/problems/last-substring-in-lexicographical-order "按字典序排在最后的子串") | [Go](https://github.com/openset/leetcode/tree/master/problems/last-substring-in-lexicographical-order) | Hard | +| 1162 | [As Far from Land as Possible](https://leetcode.com/problems/as-far-from-land-as-possible "地图分析") | [Go](https://github.com/openset/leetcode/tree/master/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](https://github.com/openset/leetcode/tree/master/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](https://github.com/openset/leetcode/tree/master/problems/find-words-that-can-be-formed-by-characters) | Easy | +| 1159 | [Market Analysis II](https://leetcode.com/problems/market-analysis-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/market-analysis-ii) | Hard | +| 1158 | [Market Analysis I](https://leetcode.com/problems/market-analysis-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/market-analysis-i) | Medium | | 1157 | [Online Majority Element In Subarray](https://leetcode.com/problems/online-majority-element-in-subarray "子数组中占绝大多数的元素") | [Go](https://github.com/openset/leetcode/tree/master/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](https://github.com/openset/leetcode/tree/master/problems/swap-for-longest-repeated-character-substring) | Medium | | 1155 | [Number of Dice Rolls With Target Sum](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum "掷骰子的N种方法") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-dice-rolls-with-target-sum) | Medium | @@ -142,7 +148,7 @@ LeetCode Problems' Solutions | 1072 | [Flip Columns For Maximum Number of Equal Rows](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows "按列翻转得到最大值等行数") | [Go](https://github.com/openset/leetcode/tree/master/problems/flip-columns-for-maximum-number-of-equal-rows) | Medium | | 1071 | [Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings "字符串的最大公因子") | [Go](https://github.com/openset/leetcode/tree/master/problems/greatest-common-divisor-of-strings) | Easy | | 1070 | [Product Sales Analysis III](https://leetcode.com/problems/product-sales-analysis-iii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-iii) | Medium | -| 1069 | [Product Sales Analysis II](https://leetcode.com/problems/product-sales-analysis-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-ii) | Easy | +| 1069 | [Product Sales Analysis II](https://leetcode.com/problems/product-sales-analysis-ii "销售分析Ⅱ") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-ii) | Easy | | 1068 | [Product Sales Analysis I](https://leetcode.com/problems/product-sales-analysis-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-i) | Easy | | 1067 | [Digit Count in Range](https://leetcode.com/problems/digit-count-in-range "范围内的数字计数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/digit-count-in-range) | Hard | | 1066 | [Campus Bikes II](https://leetcode.com/problems/campus-bikes-ii "校园自行车分配 II") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/campus-bikes-ii) | Medium | diff --git a/problems/as-far-from-land-as-possible/README.md b/problems/as-far-from-land-as-possible/README.md new file mode 100644 index 000000000..6e3ed5e2c --- /dev/null +++ b/problems/as-far-from-land-as-possible/README.md @@ -0,0 +1,79 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/maximum-level-sum-of-a-binary-tree "Maximum Level Sum of a Binary Tree") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/last-substring-in-lexicographical-order "Last Substring in Lexicographical Order") + +## 1162. As Far from Land as Possible (Medium) + +

Given an N x N grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized and return the distance.

+ +

The distance used in this problem is the Manhattan distance: the distance between two cells (x0, y0) and (x1, y1) is |x0 - x1| + |y0 - y1|.

+ +

If no land or water exists in the grid, return -1.

+ +

 

+ +

Example 1:

+ +

+ +
+Input: [[1,0,1],[0,0,0],[1,0,1]]
+Output: 2
+Explanation: 
+The cell (1, 1) is as far as possible from all the land with distance 2.
+
+ +

Example 2:

+ +

+ +
+Input: [[1,0,0],[0,0,0],[0,0,0]]
+Output: 4
+Explanation: 
+The cell (2, 2) is as far as possible from all the land with distance 4.
+
+ +

 

+ +

Note:

+ +
    +
  1. 1 <= grid.length == grid[0].length <= 100
  2. +
  3. grid[i][j] is 0 or 1
  4. +
+ +### Related Topics + [[Breadth-first Search](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)] + [[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] + +### Similar Questions + 1. [Shortest Distance from All Buildings](https://github.com/openset/leetcode/tree/master/problems/shortest-distance-from-all-buildings) (Hard) + +### Hints +
+Hint 1 +Can you think of this problem in a backwards way ? +
+ +
+Hint 2 +Imagine expanding outward from each land cell. What kind of search does that ? +
+ +
+Hint 3 +Use BFS starting from all land cells in the same time. +
+ +
+Hint 4 +When do you reach the furthest water cell? +
diff --git a/problems/best-time-to-buy-and-sell-stock-iv/README.md b/problems/best-time-to-buy-and-sell-stock-iv/README.md index 20f68b898..9b0c7eb63 100644 --- a/problems/best-time-to-buy-and-sell-stock-iv/README.md +++ b/problems/best-time-to-buy-and-sell-stock-iv/README.md @@ -11,7 +11,7 @@ ## 188. Best Time to Buy and Sell Stock IV (Hard) -

Say you have an array for which the ith element is the price of a given stock on day i.

+

Say you have an array for which the i-th element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete at most k transactions.

diff --git a/problems/brace-expansion-ii/README.md b/problems/brace-expansion-ii/README.md index 230a6e45c..db7b51ee2 100644 --- a/problems/brace-expansion-ii/README.md +++ b/problems/brace-expansion-ii/README.md @@ -80,6 +80,9 @@ ### Related Topics [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] +### Similar Questions + 1. [Brace Expansion](https://github.com/openset/leetcode/tree/master/problems/brace-expansion) (Medium) + ### Hints
Hint 1 diff --git a/problems/brace-expansion/README.md b/problems/brace-expansion/README.md index 7925c3a90..ee98ab2df 100644 --- a/problems/brace-expansion/README.md +++ b/problems/brace-expansion/README.md @@ -19,6 +19,7 @@ ### Similar Questions 1. [Decode String](https://github.com/openset/leetcode/tree/master/problems/decode-string) (Medium) 1. [Letter Case Permutation](https://github.com/openset/leetcode/tree/master/problems/letter-case-permutation) (Easy) + 1. [Brace Expansion II](https://github.com/openset/leetcode/tree/master/problems/brace-expansion-ii) (Hard) ### Hints
diff --git a/problems/convert-sorted-list-to-binary-search-tree/README.md b/problems/convert-sorted-list-to-binary-search-tree/README.md index 7e011589c..e9e43f0a0 100644 --- a/problems/convert-sorted-list-to-binary-search-tree/README.md +++ b/problems/convert-sorted-list-to-binary-search-tree/README.md @@ -30,8 +30,8 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig ### Related Topics - [[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)] + [[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] ### Similar Questions 1. [Convert Sorted Array to Binary Search Tree](https://github.com/openset/leetcode/tree/master/problems/convert-sorted-array-to-binary-search-tree) (Easy) diff --git a/problems/day-of-the-year/README.md b/problems/day-of-the-year/README.md index b204f31ba..173fb4a7f 100644 --- a/problems/day-of-the-year/README.md +++ b/problems/day-of-the-year/README.md @@ -51,3 +51,12 @@
  • date[4] == date[7] == '-', and all other date[i]'s are digits
  • date represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.
  • + +### Related Topics + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] + +### Hints +
    +Hint 1 +Have a integer array of how many days there are per month. February gets one extra day if its a leap year. Then, we can manually count the ordinal as day + (number of days in months before this one). +
    diff --git a/problems/find-words-that-can-be-formed-by-characters/README.md b/problems/find-words-that-can-be-formed-by-characters/README.md new file mode 100644 index 000000000..cd10224e8 --- /dev/null +++ b/problems/find-words-that-can-be-formed-by-characters/README.md @@ -0,0 +1,73 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/market-analysis-ii "Market Analysis II") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/maximum-level-sum-of-a-binary-tree "Maximum Level Sum of a Binary Tree") + +## 1160. Find Words That Can Be Formed by Characters (Easy) + +

    You are given an array of strings words and a string chars.

    + +

    A string is good if it can be formed by characters from chars (each character can only be used once).

    + +

    Return the sum of lengths of all good strings in words.

    + +

     

    + +

    Example 1:

    + +
    +Input: words = ["cat","bt","hat","tree"], chars = "atach"
    +Output: 6
    +Explanation: 
    +The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
    +
    + +

    Example 2:

    + +
    +Input: words = ["hello","world","leetcode"], chars = "welldonehoneyr"
    +Output: 10
    +Explanation: 
    +The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.
    +
    + +

     

    + +

    Note:

    + +
      +
    1. 1 <= words.length <= 1000
    2. +
    3. 1 <= words[i].length, chars.length <= 100
    4. +
    5. All strings contain lowercase English letters only.
    6. +
    + +### Related Topics + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] + [[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] + +### Hints +
    +Hint 1 +Solve the problem for each string in words independently. +
    + +
    +Hint 2 +Now try to think in frequency of letters. +
    + +
    +Hint 3 +Count how many times each character occurs in string chars. +
    + +
    +Hint 4 +To form a string using characters from chars, the frequency of each character in chars must be greater than or equal the frequency of that character in the string to be formed. +
    diff --git a/problems/inorder-successor-in-bst/README.md b/problems/inorder-successor-in-bst/README.md index 7b2f23db0..bc8d4b7a7 100644 --- a/problems/inorder-successor-in-bst/README.md +++ b/problems/inorder-successor-in-bst/README.md @@ -11,7 +11,34 @@ ## 285. Inorder Successor in BST (Medium) +

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST.

    +

    The successor of a node p is the node with the smallest key greater than p.val.

    + +

     

    + +

    Example 1:

    + +
    Input: root = [2,1,3], p = 1
    +Output: 2
    +Explanation: 1's in-order successor node is 2. Note that both p and the return value is of TreeNode type.
    +
    + +

    Example 2:

    + +
    Input: root = [5,3,6,2,4,null,null,1], p = 6
    +Output: null
    +Explanation: There is no in-order successor of the current node, so the answer is null.
    +
    + +

     

    + +

    Note:

    + +
      +
    1. If the given node has no in-order successor in the tree, return null.
    2. +
    3. It's guaranteed that the values of the tree are unique.
    4. +
    ### Related Topics [[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)] diff --git a/problems/last-substring-in-lexicographical-order/README.md b/problems/last-substring-in-lexicographical-order/README.md new file mode 100644 index 000000000..0e01a431c --- /dev/null +++ b/problems/last-substring-in-lexicographical-order/README.md @@ -0,0 +1,64 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/as-far-from-land-as-possible "As Far from Land as Possible") +                 +Next > + +## 1163. Last Substring in Lexicographical Order (Hard) + +

    Given a string s, return the last substring of s in lexicographical order.

    + +

     

    + +

    Example 1:

    + +
    +Input: "abab"
    +Output: "bab"
    +Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".
    +
    + +

    Example 2:

    + +
    +Input: "leetcode"
    +Output: "tcode"
    +
    + +

     

    + +

    Note:

    + +
      +
    1. 1 <= s.length <= 10^5
    2. +
    3. s contains only lowercase English letters.
    4. +
    + +### Related Topics + [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] + +### Hints +
    +Hint 1 +Assume that the answer is a sub-string from index i to j. If you add the character at index j+1 you get a better answer. +
    + +
    +Hint 2 +The answer is always a suffix of the given string. +
    + +
    +Hint 3 +Since the limits are high, we need an efficient data structure. +
    + +
    +Hint 4 +Use suffix array. +
    diff --git a/problems/market-analysis-i/README.md b/problems/market-analysis-i/README.md new file mode 100644 index 000000000..5df2b797b --- /dev/null +++ b/problems/market-analysis-i/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/online-majority-element-in-subarray "Online Majority Element In Subarray") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/market-analysis-ii "Market Analysis II") + +## 1158. Market Analysis I (Medium) + + diff --git a/problems/market-analysis-i/mysql_schemas.sql b/problems/market-analysis-i/mysql_schemas.sql new file mode 100644 index 000000000..31eafa569 --- /dev/null +++ b/problems/market-analysis-i/mysql_schemas.sql @@ -0,0 +1,20 @@ +Create table If Not Exists Users (user_id int, join_date date, favorite_brand varchar(10)); +create table if not exists Orders (order_id int, order_date date, item_id int, buyer_id int, seller_id int); +create table if not exists Items (item_id int, item_brand varchar(10)); +Truncate table Users; +insert into Users (user_id, join_date, favorite_brand) values ('1', '2018-01-01', 'Lenovo'); +insert into Users (user_id, join_date, favorite_brand) values ('2', '2018-02-09', 'Samsung'); +insert into Users (user_id, join_date, favorite_brand) values ('3', '2018-01-19', 'LG'); +insert into Users (user_id, join_date, favorite_brand) values ('4', '2018-05-21', 'HP'); +Truncate table Orders; +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('1', '2019-08-01', '4', '1', '2'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('2', '2018-08-02', '2', '1', '3'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('3', '2019-08-03', '3', '2', '3'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('4', '2018-08-04', '1', '4', '2'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('5', '2018-08-04', '1', '3', '4'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('6', '2019-08-05', '2', '2', '4'); +Truncate table Items; +insert into Items (item_id, item_brand) values ('1', 'Samsung'); +insert into Items (item_id, item_brand) values ('2', 'Lenovo'); +insert into Items (item_id, item_brand) values ('3', 'LG'); +insert into Items (item_id, item_brand) values ('4', 'HP'); diff --git a/problems/market-analysis-ii/README.md b/problems/market-analysis-ii/README.md new file mode 100644 index 000000000..5b623f118 --- /dev/null +++ b/problems/market-analysis-ii/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/market-analysis-i "Market Analysis I") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/find-words-that-can-be-formed-by-characters "Find Words That Can Be Formed by Characters") + +## 1159. Market Analysis II (Hard) + + diff --git a/problems/market-analysis-ii/mysql_schemas.sql b/problems/market-analysis-ii/mysql_schemas.sql new file mode 100644 index 000000000..2932728aa --- /dev/null +++ b/problems/market-analysis-ii/mysql_schemas.sql @@ -0,0 +1,20 @@ +Create table If Not Exists Users (user_id int, join_date date, favorite_brand varchar(10)); +create table if not exists Orders (order_id int, order_date date, item_id int, buyer_id int, seller_id int); +create table if not exists Items (item_id int, item_brand varchar(10)); +Truncate table Users; +insert into Users (user_id, join_date, favorite_brand) values ('1', '2019-01-01', 'Lenovo'); +insert into Users (user_id, join_date, favorite_brand) values ('2', '2019-02-09', 'Samsung'); +insert into Users (user_id, join_date, favorite_brand) values ('3', '2019-01-19', 'LG'); +insert into Users (user_id, join_date, favorite_brand) values ('4', '2019-05-21', 'HP'); +Truncate table Orders; +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('1', '2019-08-01', '4', '1', '2'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('2', '2019-08-02', '2', '1', '3'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('3', '2019-08-03', '3', '2', '3'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('4', '2019-08-04', '1', '4', '2'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('5', '2019-08-04', '1', '3', '4'); +insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('6', '2019-08-05', '2', '2', '4'); +Truncate table Items; +insert into Items (item_id, item_brand) values ('1', 'Samsung'); +insert into Items (item_id, item_brand) values ('2', 'Lenovo'); +insert into Items (item_id, item_brand) values ('3', 'LG'); +insert into Items (item_id, item_brand) values ('4', 'HP'); diff --git a/problems/maximum-level-sum-of-a-binary-tree/README.md b/problems/maximum-level-sum-of-a-binary-tree/README.md new file mode 100644 index 000000000..fec43eba2 --- /dev/null +++ b/problems/maximum-level-sum-of-a-binary-tree/README.md @@ -0,0 +1,65 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-words-that-can-be-formed-by-characters "Find Words That Can Be Formed by Characters") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/as-far-from-land-as-possible "As Far from Land as Possible") + +## 1161. Maximum Level Sum of a Binary Tree (Medium) + +

    Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.

    + +

    Return the smallest level X such that the sum of all the values of nodes at level X is maximal.

    + +

     

    + +

    Example 1:

    + +

    + +
    +Input: [1,7,0,7,-8,null,null]
    +Output: 2
    +Explanation: 
    +Level 1 sum = 1.
    +Level 2 sum = 7 + 0 = 7.
    +Level 3 sum = 7 + -8 = -1.
    +So we return the level with the maximum sum which is level 2.
    +
    + +

     

    + +

    Note:

    + +
      +
    1. The number of nodes in the given tree is between 1 and 10^4.
    2. +
    3. -10^5 <= node.val <= 10^5
    4. +
    + +### Related Topics + [[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] + +### Hints +
    +Hint 1 +Calculate the sum for each level then find the level with the maximum sum. +
    + +
    +Hint 2 +How can you traverse the tree ? +
    + +
    +Hint 3 +How can you sum up the values for every level ? +
    + +
    +Hint 4 +Use DFS or BFS to traverse the tree keeping the level of each node, and sum up those values with a map or a frequency array. +
    diff --git a/problems/online-majority-element-in-subarray/README.md b/problems/online-majority-element-in-subarray/README.md index c96b54ddd..c39765f10 100644 --- a/problems/online-majority-element-in-subarray/README.md +++ b/problems/online-majority-element-in-subarray/README.md @@ -7,7 +7,7 @@ [< Previous](https://github.com/openset/leetcode/tree/master/problems/swap-for-longest-repeated-character-substring "Swap For Longest Repeated Character Substring")                  -Next > +[Next >](https://github.com/openset/leetcode/tree/master/problems/market-analysis-i "Market Analysis I") ## 1157. Online Majority Element In Subarray (Hard) diff --git a/problems/shortest-distance-from-all-buildings/README.md b/problems/shortest-distance-from-all-buildings/README.md index 02bf4bea6..c3d811537 100644 --- a/problems/shortest-distance-from-all-buildings/README.md +++ b/problems/shortest-distance-from-all-buildings/README.md @@ -19,3 +19,4 @@ ### Similar Questions 1. [Walls and Gates](https://github.com/openset/leetcode/tree/master/problems/walls-and-gates) (Medium) 1. [Best Meeting Point](https://github.com/openset/leetcode/tree/master/problems/best-meeting-point) (Hard) + 1. [As Far from Land as Possible](https://github.com/openset/leetcode/tree/master/problems/as-far-from-land-as-possible) (Medium) diff --git a/problems/swap-for-longest-repeated-character-substring/README.md b/problems/swap-for-longest-repeated-character-substring/README.md index 3ea86537b..5f4cb4264 100644 --- a/problems/swap-for-longest-repeated-character-substring/README.md +++ b/problems/swap-for-longest-repeated-character-substring/README.md @@ -59,3 +59,13 @@
  • 1 <= text.length <= 20000
  • text consist of lowercase English characters only.
  • + +### Related Topics + [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] + +### Hints +
    +Hint 1 +There are two cases: a block of characters, or two blocks of characters between one different character. + By keeping a run-length encoded version of the string, we can easily check these cases. +
    diff --git a/tag/README.md b/tag/README.md index 099376dc1..862a51ec2 100644 --- a/tag/README.md +++ b/tag/README.md @@ -17,11 +17,11 @@ | 11 | [Breadth-first Search](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md) | [广度优先搜索](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md) | | 12 | [Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md) | [栈](https://github.com/openset/leetcode/tree/master/tag/stack/README.md) | | 13 | [Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md) | [回溯算法](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md) | | 14 | [Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md) | [设计](https://github.com/openset/leetcode/tree/master/tag/design/README.md) | | 15 | [Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md) | [链表](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md) | | 16 | [Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md) | [排序](https://github.com/openset/leetcode/tree/master/tag/sort/README.md) | -| 17 | [Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md) | [位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md) | | 18 | [Heap](https://github.com/openset/leetcode/tree/master/tag/heap/README.md) | [堆](https://github.com/openset/leetcode/tree/master/tag/heap/README.md) | -| 19 | [Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md) | [图](https://github.com/openset/leetcode/tree/master/tag/graph/README.md) | | 20 | [Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md) | [并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md) | +| 17 | [Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md) | [位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md) | | 18 | [Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md) | [图](https://github.com/openset/leetcode/tree/master/tag/graph/README.md) | +| 19 | [Heap](https://github.com/openset/leetcode/tree/master/tag/heap/README.md) | [堆](https://github.com/openset/leetcode/tree/master/tag/heap/README.md) | | 20 | [Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md) | [并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md) | | 21 | [Divide and Conquer](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md) | [分治算法](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md) | | 22 | [Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md) | [Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md) | | 23 | [Trie](https://github.com/openset/leetcode/tree/master/tag/trie/README.md) | [字典树](https://github.com/openset/leetcode/tree/master/tag/trie/README.md) | | 24 | [Recursion](https://github.com/openset/leetcode/tree/master/tag/recursion/README.md) | [递归](https://github.com/openset/leetcode/tree/master/tag/recursion/README.md) | -| 25 | [Ordered Map](https://github.com/openset/leetcode/tree/master/tag/ordered-map/README.md) | [Ordered Map](https://github.com/openset/leetcode/tree/master/tag/ordered-map/README.md) | | 26 | [Segment Tree](https://github.com/openset/leetcode/tree/master/tag/segment-tree/README.md) | [线段树](https://github.com/openset/leetcode/tree/master/tag/segment-tree/README.md) | +| 25 | [Segment Tree](https://github.com/openset/leetcode/tree/master/tag/segment-tree/README.md) | [线段树](https://github.com/openset/leetcode/tree/master/tag/segment-tree/README.md) | | 26 | [Ordered Map](https://github.com/openset/leetcode/tree/master/tag/ordered-map/README.md) | [Ordered Map](https://github.com/openset/leetcode/tree/master/tag/ordered-map/README.md) | | 27 | [Queue](https://github.com/openset/leetcode/tree/master/tag/queue/README.md) | [队列](https://github.com/openset/leetcode/tree/master/tag/queue/README.md) | | 28 | [Minimax](https://github.com/openset/leetcode/tree/master/tag/minimax/README.md) | [极小化极大](https://github.com/openset/leetcode/tree/master/tag/minimax/README.md) | | 29 | [Binary Indexed Tree](https://github.com/openset/leetcode/tree/master/tag/binary-indexed-tree/README.md) | [树状数组](https://github.com/openset/leetcode/tree/master/tag/binary-indexed-tree/README.md) | | 30 | [Random](https://github.com/openset/leetcode/tree/master/tag/random/README.md) | [Random](https://github.com/openset/leetcode/tree/master/tag/random/README.md) | | 31 | [Topological Sort](https://github.com/openset/leetcode/tree/master/tag/topological-sort/README.md) | [拓扑排序](https://github.com/openset/leetcode/tree/master/tag/topological-sort/README.md) | | 32 | [Brainteaser](https://github.com/openset/leetcode/tree/master/tag/brainteaser/README.md) | [脑筋急转弯](https://github.com/openset/leetcode/tree/master/tag/brainteaser/README.md) | diff --git a/tag/tags.json b/tag/tags.json index e6ecbbdca..66241f62f 100644 --- a/tag/tags.json +++ b/tag/tags.json @@ -84,16 +84,16 @@ "Slug": "bit-manipulation", "TranslatedName": "位运算" }, - { - "Name": "Heap", - "Slug": "heap", - "TranslatedName": "堆" - }, { "Name": "Graph", "Slug": "graph", "TranslatedName": "图" }, + { + "Name": "Heap", + "Slug": "heap", + "TranslatedName": "堆" + }, { "Name": "Union Find", "Slug": "union-find", @@ -119,16 +119,16 @@ "Slug": "recursion", "TranslatedName": "递归" }, - { - "Name": "Ordered Map", - "Slug": "ordered-map", - "TranslatedName": "Ordered Map" - }, { "Name": "Segment Tree", "Slug": "segment-tree", "TranslatedName": "线段树" }, + { + "Name": "Ordered Map", + "Slug": "ordered-map", + "TranslatedName": "Ordered Map" + }, { "Name": "Queue", "Slug": "queue",