From b7fdc4baa28cdef82a8ce22a638c02321bfdfae6 Mon Sep 17 00:00:00 2001 From: Shuo Date: Mon, 17 Aug 2020 12:57:19 +0800 Subject: [PATCH] A: new --- README.md | 16 ++-- problems/can-i-win/README.md | 49 +++++++---- problems/combinations/README.md | 22 ++++- problems/course-schedule-ii/README.md | 2 +- problems/customer-order-frequency/README.md | 2 +- .../README.md | 68 +++++++++++++++ problems/distribute-candies/README.md | 68 +++++++++++---- problems/find-duplicate-subtrees/README.md | 43 ++++++---- .../find-users-with-valid-e-mails/README.md | 2 +- problems/fix-product-name-format/README.md | 2 +- problems/friend-circles/README.md | 39 +++++---- problems/implement-trie-prefix-tree/README.md | 2 +- problems/letter-case-permutation/README.md | 27 +++++- problems/letter-tile-possibilities/README.md | 29 ++++--- .../README.md | 2 +- .../longest-arithmetic-subsequence/README.md | 55 ++++++++++++ .../README.md | 66 ++++++++++++++ .../README.md | 2 +- problems/merge-k-sorted-lists/README.md | 48 +++++++++-- .../minimum-cost-to-cut-a-stick/README.md | 2 +- .../README.md | 83 ++++++++++++++++++ .../README.md | 4 +- .../README.md | 82 ++++++++++++++++++ .../README.md | 57 ++++++++++++ .../move-sub-tree-of-n-ary-tree/README.md | 2 +- .../README.md | 10 +++ problems/open-the-lock/README.md | 86 ++++++++++--------- problems/palindrome-partitioning-ii/README.md | 31 ++++++- problems/pancake-sorting/README.md | 43 ++++++---- problems/prefix-and-suffix-search/README.md | 2 +- problems/profitable-schemes/README.md | 12 +-- problems/random-pick-with-weight/README.md | 6 +- .../README.md | 2 +- problems/restore-ip-addresses/README.md | 38 +++++--- .../search-in-rotated-sorted-array/README.md | 37 ++++---- .../README.md | 2 +- problems/stone-game/README.md | 12 ++- .../README.md | 14 +++ .../mysql_schemas.sql | 25 ++++++ .../README.md | 29 +++++++ problems/three-consecutive-odds/README.md | 47 ++++++++++ problems/valid-palindrome-iii/README.md | 2 +- problems/validate-ip-address/README.md | 32 +++++-- problems/word-search-ii/README.md | 2 +- readme/1-300.md | 4 +- readme/601-900.md | 2 +- readme/901-1200.md | 2 +- tag/array/README.md | 4 +- tag/backtracking/README.md | 2 +- tag/binary-search/README.md | 1 + tag/design/README.md | 2 +- tag/divide-and-conquer/README.md | 2 +- tag/dynamic-programming/README.md | 4 +- tag/graph/README.md | 1 + tag/greedy/README.md | 4 +- tag/heap/README.md | 2 +- tag/linked-list/README.md | 2 +- tag/math/README.md | 3 +- tag/tree/README.md | 2 +- tag/trie/README.md | 2 +- 60 files changed, 998 insertions(+), 247 deletions(-) create mode 100644 problems/design-add-and-search-words-data-structure/README.md create mode 100644 problems/longest-arithmetic-subsequence/README.md create mode 100644 problems/magnetic-force-between-two-balls/README.md create mode 100644 problems/minimum-cost-to-move-chips-to-the-same-position/README.md create mode 100644 problems/minimum-number-of-days-to-eat-n-oranges/README.md create mode 100644 problems/minimum-operations-to-make-array-equal/README.md create mode 100644 problems/the-most-recent-orders-for-each-product/README.md create mode 100644 problems/the-most-recent-orders-for-each-product/mysql_schemas.sql create mode 100644 problems/the-most-similar-path-in-a-graph/README.md create mode 100644 problems/three-consecutive-odds/README.md diff --git a/README.md b/README.md index d0624c236..f536dfd67 100644 --- a/README.md +++ b/README.md @@ -70,11 +70,17 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1553 | [Minimum Number of Days to Eat N Oranges](https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges "吃掉 N 个橘子的最少天数") | [Go](problems/minimum-number-of-days-to-eat-n-oranges) | Hard | +| 1552 | [Magnetic Force Between Two Balls](https://leetcode.com/problems/magnetic-force-between-two-balls "两球之间的磁力") | [Go](problems/magnetic-force-between-two-balls) | Medium | +| 1551 | [Minimum Operations to Make Array Equal](https://leetcode.com/problems/minimum-operations-to-make-array-equal "使数组中所有元素相等的最小操作数") | [Go](problems/minimum-operations-to-make-array-equal) | Medium | +| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds "存在连续三个奇数的数组") | [Go](problems/three-consecutive-odds) | Easy | +| 1549 | [The Most Recent Orders for Each Product](https://leetcode.com/problems/the-most-recent-orders-for-each-product) 🔒 | [MySQL](problems/the-most-recent-orders-for-each-product) | Medium | +| 1548 | [The Most Similar Path in a Graph](https://leetcode.com/problems/the-most-similar-path-in-a-graph) 🔒 | [Go](problems/the-most-similar-path-in-a-graph) | Hard | | 1547 | [Minimum Cost to Cut a Stick](https://leetcode.com/problems/minimum-cost-to-cut-a-stick "切棍子的最小成本") | [Go](problems/minimum-cost-to-cut-a-stick) | Hard | | 1546 | [Maximum Number of Non-Overlapping Subarrays With Sum Equals Target](https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target "和为目标值的最大数目不重叠非空子数组数目") | [Go](problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target) | Medium | | 1545 | [Find Kth Bit in Nth Binary String](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string "找出第 N 个二进制字符串中的第 K 位") | [Go](problems/find-kth-bit-in-nth-binary-string) | Medium | | 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great "整理字符串") | [Go](problems/make-the-string-great) | Easy | -| 1543 | [Fix Product Name Format](https://leetcode.com/problems/fix-product-name-format) 🔒 | [MySQL](problems/fix-product-name-format) | Easy | +| 1543 | [Fix Product Name Format](https://leetcode.com/problems/fix-product-name-format "产品名称格式修复") 🔒 | [MySQL](problems/fix-product-name-format) | Easy | | 1542 | [Find Longest Awesome Substring](https://leetcode.com/problems/find-longest-awesome-substring "找出最长的超赞子字符串") | [Go](problems/find-longest-awesome-substring) | Hard | | 1541 | [Minimum Insertions to Balance a Parentheses String](https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string "平衡括号字符串的最少插入次数") | [Go](problems/minimum-insertions-to-balance-a-parentheses-string) | Medium | | 1540 | [Can Convert String in K Moves](https://leetcode.com/problems/can-convert-string-in-k-moves "K 次操作转变字符串") | [Go](problems/can-convert-string-in-k-moves) | Medium | @@ -100,13 +106,13 @@ LeetCode Problems' Solutions | 1520 | [Maximum Number of Non-Overlapping Substrings](https://leetcode.com/problems/maximum-number-of-non-overlapping-substrings "最多的不重叠子字符串") | [Go](problems/maximum-number-of-non-overlapping-substrings) | Hard | | 1519 | [Number of Nodes in the Sub-Tree With the Same Label](https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label "子树中标签相同的节点数") | [Go](problems/number-of-nodes-in-the-sub-tree-with-the-same-label) | Medium | | 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles "换酒问题") | [Go](problems/water-bottles) | Easy | -| 1517 | [Find Users With Valid E-Mails](https://leetcode.com/problems/find-users-with-valid-e-mails) 🔒 | [MySQL](problems/find-users-with-valid-e-mails) | Easy | -| 1516 | [Move Sub-Tree of N-Ary Tree](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree) 🔒 | [Go](problems/move-sub-tree-of-n-ary-tree) | Hard | +| 1517 | [Find Users With Valid E-Mails](https://leetcode.com/problems/find-users-with-valid-e-mails "查找拥有有效邮箱的用户") 🔒 | [MySQL](problems/find-users-with-valid-e-mails) | Easy | +| 1516 | [Move Sub-Tree of N-Ary Tree](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree "移动 N 叉树的子树") 🔒 | [Go](problems/move-sub-tree-of-n-ary-tree) | Hard | | 1515 | [Best Position for a Service Centre](https://leetcode.com/problems/best-position-for-a-service-centre "服务中心的最佳位置") | [Go](problems/best-position-for-a-service-centre) | Hard | | 1514 | [Path with Maximum Probability](https://leetcode.com/problems/path-with-maximum-probability "概率最大的路径") | [Go](problems/path-with-maximum-probability) | Medium | | 1513 | [Number of Substrings With Only 1s](https://leetcode.com/problems/number-of-substrings-with-only-1s "仅含 1 的子串数") | [Go](problems/number-of-substrings-with-only-1s) | Medium | | 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs "好数对的数目") | [Go](problems/number-of-good-pairs) | Easy | -| 1511 | [Customer Order Frequency](https://leetcode.com/problems/customer-order-frequency) 🔒 | [MySQL](problems/customer-order-frequency) | Easy | +| 1511 | [Customer Order Frequency](https://leetcode.com/problems/customer-order-frequency "消费者下单频率") 🔒 | [MySQL](problems/customer-order-frequency) | Easy | | 1510 | [Stone Game IV](https://leetcode.com/problems/stone-game-iv "石子游戏 IV") | [Go](problems/stone-game-iv) | Hard | | 1509 | [Minimum Difference Between Largest and Smallest Value in Three Moves](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves "三次操作后最大值与最小值的最小差") | [Go](problems/minimum-difference-between-largest-and-smallest-value-in-three-moves) | Medium | | 1508 | [Range Sum of Sorted Subarray Sums](https://leetcode.com/problems/range-sum-of-sorted-subarray-sums "子数组和排序后的区间和") | [Go](problems/range-sum-of-sorted-subarray-sums) | Medium | @@ -400,7 +406,7 @@ LeetCode Problems' Solutions | 1220 | [Count Vowels Permutation](https://leetcode.com/problems/count-vowels-permutation "统计元音字母序列的数目") | [Go](problems/count-vowels-permutation) | Hard | | 1219 | [Path with Maximum Gold](https://leetcode.com/problems/path-with-maximum-gold "黄金矿工") | [Go](problems/path-with-maximum-gold) | Medium | | 1218 | [Longest Arithmetic Subsequence of Given Difference](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference "最长定差子序列") | [Go](problems/longest-arithmetic-subsequence-of-given-difference) | Medium | -| 1217 | [Play with Chips](https://leetcode.com/problems/play-with-chips "玩筹码") | [Go](problems/play-with-chips) | Easy | +| 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position "玩筹码") | [Go](problems/minimum-cost-to-move-chips-to-the-same-position) | Easy | | 1216 | [Valid Palindrome III](https://leetcode.com/problems/valid-palindrome-iii "验证回文字符串 III") 🔒 | [Go](problems/valid-palindrome-iii) | Hard | | 1215 | [Stepping Numbers](https://leetcode.com/problems/stepping-numbers "步进数") 🔒 | [Go](problems/stepping-numbers) | Medium | | 1214 | [Two Sum BSTs](https://leetcode.com/problems/two-sum-bsts "查找两棵二叉搜索树之和") 🔒 | [Go](problems/two-sum-bsts) | Medium | diff --git a/problems/can-i-win/README.md b/problems/can-i-win/README.md index 8a62abcae..514ebd380 100644 --- a/problems/can-i-win/README.md +++ b/problems/can-i-win/README.md @@ -11,34 +11,49 @@ ## [464. Can I Win (Medium)](https://leetcode.com/problems/can-i-win "我能赢吗") -

In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.

+

In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins.

-

What if we change the game so that players cannot re-use integers?

+

What if we change the game so that players cannot re-use integers?

-

For example, two players might take turns drawing from a common pool of numbers of 1..15 without replacement until they reach a total >= 100.

+

For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.

-

Given an integer maxChoosableInteger and another integer desiredTotal, determine if the first player to move can force a win, assuming both players play optimally.

+

Given two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise return false. Assume both players play optimally.

-

You can always assume that maxChoosableInteger will not be larger than 20 and desiredTotal will not be larger than 300. -

+

 

+

Example 1:

-

Example

-Input:
-maxChoosableInteger = 10
-desiredTotal = 11
-
-Output:
-false
-
-Explanation:
+Input: maxChoosableInteger = 10, desiredTotal = 11
+Output: false
+Explanation:
 No matter which integer the first player choose, the first player will lose.
 The first player can choose an integer from 1 up to 10.
 If the first player choose 1, the second player can only choose integers from 2 up to 10.
-The second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.
+The second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.
 Same with other integers chosen by the first player, the second player will always win.
 
-

+ +

Example 2:

+ +
+Input: maxChoosableInteger = 10, desiredTotal = 0
+Output: true
+
+ +

Example 3:

+ +
+Input: maxChoosableInteger = 10, desiredTotal = 1
+Output: true
+
+ +

 

+

Constraints:

+ + ### Related Topics [[Minimax](../../tag/minimax/README.md)] diff --git a/problems/combinations/README.md b/problems/combinations/README.md index 196e8c701..a3aaa438f 100644 --- a/problems/combinations/README.md +++ b/problems/combinations/README.md @@ -13,10 +13,13 @@

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

-

Example:

+

You may return the answer in any order.

+ +

 

+

Example 1:

-Input: n = 4, k = 2
+Input: n = 4, k = 2
 Output:
 [
   [2,4],
@@ -28,6 +31,21 @@
 ]
 
+

Example 2:

+ +
+Input: n = 1, k = 1
+Output: [[1]]
+
+ +

 

+

Constraints:

+ + + ### Related Topics [[Backtracking](../../tag/backtracking/README.md)] diff --git a/problems/course-schedule-ii/README.md b/problems/course-schedule-ii/README.md index fa278ad52..fa7145a47 100644 --- a/problems/course-schedule-ii/README.md +++ b/problems/course-schedule-ii/README.md @@ -7,7 +7,7 @@ [< Previous](../minimum-size-subarray-sum "Minimum Size Subarray Sum")                  -[Next >](../add-and-search-word-data-structure-design "Add and Search Word - Data structure design") +[Next >](../design-add-and-search-words-data-structure "Design Add and Search Words Data Structure") ## [210. Course Schedule II (Medium)](https://leetcode.com/problems/course-schedule-ii "课程表 II") diff --git a/problems/customer-order-frequency/README.md b/problems/customer-order-frequency/README.md index 987168901..e4487f01e 100644 --- a/problems/customer-order-frequency/README.md +++ b/problems/customer-order-frequency/README.md @@ -9,6 +9,6 @@                  [Next >](../number-of-good-pairs "Number of Good Pairs") -## [1511. Customer Order Frequency (Easy)](https://leetcode.com/problems/customer-order-frequency "") +## [1511. Customer Order Frequency (Easy)](https://leetcode.com/problems/customer-order-frequency "消费者下单频率") diff --git a/problems/design-add-and-search-words-data-structure/README.md b/problems/design-add-and-search-words-data-structure/README.md new file mode 100644 index 000000000..999e4a8f8 --- /dev/null +++ b/problems/design-add-and-search-words-data-structure/README.md @@ -0,0 +1,68 @@ + + + + + + + +[< Previous](../course-schedule-ii "Course Schedule II") +                 +[Next >](../word-search-ii "Word Search II") + +## [211. Design Add and Search Words Data Structure (Medium)](https://leetcode.com/problems/design-add-and-search-words-data-structure "添加与搜索单词 - 数据结构设计") + +

You should design a data structure that supports adding new words and finding if a string matches any previously added string.

+ +

Implement the WordDictionary class:

+ + + +

 

+

Example:

+ +
+Input
+["WordDictionary","addWord","addWord","addWord","search","search","search","search"]
+[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
+Output
+[null,null,null,null,false,true,true,true]
+
+Explanation
+WordDictionary wordDictionary = new WordDictionary();
+wordDictionary.addWord("bad");
+wordDictionary.addWord("dad");
+wordDictionary.addWord("mad");
+wordDictionary.search("pad"); // return False
+wordDictionary.search("bad"); // return True
+wordDictionary.search(".ad"); // return True
+wordDictionary.search("b.."); // return True
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Design](../../tag/design/README.md)] + [[Trie](../../tag/trie/README.md)] + [[Backtracking](../../tag/backtracking/README.md)] + +### Similar Questions + 1. [Implement Trie (Prefix Tree)](../implement-trie-prefix-tree) (Medium) + 1. [Prefix and Suffix Search](../prefix-and-suffix-search) (Hard) + +### Hints +
+Hint 1 +You should be familiar with how a Trie works. If not, please work on this problem: Implement Trie (Prefix Tree) first. +
diff --git a/problems/distribute-candies/README.md b/problems/distribute-candies/README.md index 38dff1ca2..9cfd5e983 100644 --- a/problems/distribute-candies/README.md +++ b/problems/distribute-candies/README.md @@ -11,34 +11,66 @@ ## [575. Distribute Candies (Easy)](https://leetcode.com/problems/distribute-candies "分糖果") -Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these candies equally in number to brother and sister. Return the maximum number of kinds of candies the sister could gain. +

You have n candies of different types, the ith candy is of type candies[i].

+ +

You want to distribute the candies equally between a sister and a brother so that each of them gets n / 2 candies (n is even). The sister loves to collect different types of candies, so you want to give her the maximum number of different types of candies.

+ +

Return the maximum number of different types of candies you can give to the sister.

+ +
    +
+ +

 

+

Example 1:

-

Example 1:

-Input: candies = [1,1,2,2,3,3]
-Output: 3
-Explanation:
+Input: candies = [1,1,2,2,3,3]
+Output: 3
+Explanation:
 There are three different kinds of candies (1, 2 and 3), and two candies for each kind.
 Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too. 
 The sister has three different kinds of candies. 
 
-

-

Example 2:
+

Example 2:

+
-Input: candies = [1,1,2,3]
-Output: 2
-Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1]. 
-The sister has two different kinds of candies, the brother has only one kind of candies. 
+Input: candies = [1,1,2,3]
+Output: 2
+Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1]. 
+The sister has two different kinds of candies, the brother has only one kind of candies.
 
-

-

Note: -

    -
  1. The length of the given array is in range [2, 10,000], and will be even.
  2. -
  3. The number in given array is in range [-100,000, 100,000].
  4. -
      -

      +

      Example 3:

      + +
      +Input: candies = [1,1]
      +Output: 1
      +
      + +

      Example 4:

      + +
      +Input: candies = [1,11]
      +Output: 1
      +
      + +

      Example 5:

      + +
      +Input: candies = [2,2]
      +Output: 1
      +
      + +

       

      +

      Constraints:

      + +
        +
      • n == candies.length
      • +
      • 2 <= n <= 10^4
      • +
      • n is even.
      • +
      • -10^5 <= candies[i] <= 10^5
      • +
      ### Related Topics [[Hash Table](../../tag/hash-table/README.md)] diff --git a/problems/find-duplicate-subtrees/README.md b/problems/find-duplicate-subtrees/README.md index 649d1408c..05d1c580c 100644 --- a/problems/find-duplicate-subtrees/README.md +++ b/problems/find-duplicate-subtrees/README.md @@ -11,36 +11,41 @@ ## [652. Find Duplicate Subtrees (Medium)](https://leetcode.com/problems/find-duplicate-subtrees "寻找重复的子树") -

      Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.

      +

      Given the root of a binary tree, return all duplicate subtrees.

      -

      Two trees are duplicate if they have the same structure with same node values.

      +

      For each kind of duplicate subtrees, you only need to return the root node of any one of them.

      -

      Example 1:

      +

      Two trees are duplicate if they have the same structure with the same node values.

      +

       

      +

      Example 1:

      +
      -        1
      -       / \
      -      2   3
      -     /   / \
      -    4   2   4
      -       /
      -      4
      +Input: root = [1,2,3,4,null,2,4,null,null,4]
      +Output: [[2,4],[4]]
       
      -

      The following are two duplicate subtrees:

      - +

      Example 2:

      +
      -      2
      -     /
      -    4
      +Input: root = [2,1,1]
      +Output: [[1]]
       
      -

      and

      - +

      Example 3:

      +
      -    4
      +Input: root = [2,2,2,3,null,3,null]
      +Output: [[2,3],[3]]
       
      -Therefore, you need to return above trees' root in the form of a list. + +

       

      +

      Constraints:

      + +
        +
      • The number of the nodes in the tree will be in the range [1, 10^4]
      • +
      • -200 <= Node.val <= 200
      • +
      ### Related Topics [[Tree](../../tag/tree/README.md)] diff --git a/problems/find-users-with-valid-e-mails/README.md b/problems/find-users-with-valid-e-mails/README.md index ce7862879..40adfeae3 100644 --- a/problems/find-users-with-valid-e-mails/README.md +++ b/problems/find-users-with-valid-e-mails/README.md @@ -9,6 +9,6 @@                  [Next >](../water-bottles "Water Bottles") -## [1517. Find Users With Valid E-Mails (Easy)](https://leetcode.com/problems/find-users-with-valid-e-mails "") +## [1517. Find Users With Valid E-Mails (Easy)](https://leetcode.com/problems/find-users-with-valid-e-mails "查找拥有有效邮箱的用户") diff --git a/problems/fix-product-name-format/README.md b/problems/fix-product-name-format/README.md index cc674b4fb..fe5827009 100644 --- a/problems/fix-product-name-format/README.md +++ b/problems/fix-product-name-format/README.md @@ -9,6 +9,6 @@                  [Next >](../make-the-string-great "Make The String Great") -## [1543. Fix Product Name Format (Easy)](https://leetcode.com/problems/fix-product-name-format "") +## [1543. Fix Product Name Format (Easy)](https://leetcode.com/problems/fix-product-name-format "产品名称格式修复") diff --git a/problems/friend-circles/README.md b/problems/friend-circles/README.md index d8eb27439..dea5595e2 100644 --- a/problems/friend-circles/README.md +++ b/problems/friend-circles/README.md @@ -11,44 +11,45 @@ ## [547. Friend Circles (Medium)](https://leetcode.com/problems/friend-circles "朋友圈") -

      -There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined a friend circle is a group of students who are direct or indirect friends. -

      +

      There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined a friend circle is a group of students who are direct or indirect friends.

      -

      -Given a N*N matrix M representing the friend relationship between students in the class. If M[i][j] = 1, then the ith and jth students are direct friends with each other, otherwise not. And you have to output the total number of friend circles among all the students. -

      +

      Given a N*N matrix M representing the friend relationship between students in the class. If M[i][j] = 1, then the ith and jth students are direct friends with each other, otherwise not. And you have to output the total number of friend circles among all the students.

      + +

      Example 1:

      -

      Example 1:

       Input: 
       [[1,1,0],
        [1,1,0],
        [0,0,1]]
       Output: 2
      -Explanation:The 0th and 1st students are direct friends, so they are in a friend circle. 
      The 2nd student himself is in a friend circle. So return 2. +Explanation:The 0th and 1st students are direct friends, so they are in a friend circle. +The 2nd student himself is in a friend circle. So return 2.
      -

      -

      Example 2:
      +

       

      + +

      Example 2:

      +
       Input: 
       [[1,1,0],
        [1,1,1],
        [0,1,1]]
       Output: 1
      -Explanation:The 0th and 1st students are direct friends, the 1st and 2nd students are direct friends, 
      so the 0th and 2nd students are indirect friends. All of them are in the same friend circle, so return 1. +Explanation:The 0th and 1st students are direct friends, the 1st and 2nd students are direct friends, +so the 0th and 2nd students are indirect friends. All of them are in the same friend circle, so return 1. +
      -

      +

       

      +

      Constraints:

      -

      Note:
      -

        -
      1. N is in range [1,200].
      2. -
      3. M[i][i] = 1 for all students.
      4. -
      5. If M[i][j] = 1, then M[j][i] = 1.
      6. -
      -

      +
        +
      • 1 <= N <= 200
      • +
      • M[i][i] == 1
      • +
      • M[i][j] == M[j][i]
      • +
      ### Related Topics [[Depth-first Search](../../tag/depth-first-search/README.md)] diff --git a/problems/implement-trie-prefix-tree/README.md b/problems/implement-trie-prefix-tree/README.md index 4435545a4..00bcce42e 100644 --- a/problems/implement-trie-prefix-tree/README.md +++ b/problems/implement-trie-prefix-tree/README.md @@ -38,7 +38,7 @@ trie.search("app"); // returns true [[Trie](../../tag/trie/README.md)] ### Similar Questions - 1. [Add and Search Word - Data structure design](../add-and-search-word-data-structure-design) (Medium) + 1. [Design Add and Search Words Data Structure](../design-add-and-search-words-data-structure) (Medium) 1. [Design Search Autocomplete System](../design-search-autocomplete-system) (Hard) 1. [Replace Words](../replace-words) (Medium) 1. [Implement Magic Dictionary](../implement-magic-dictionary) (Medium) diff --git a/problems/letter-case-permutation/README.md b/problems/letter-case-permutation/README.md index 7df90a000..1fb8f93de 100644 --- a/problems/letter-case-permutation/README.md +++ b/problems/letter-case-permutation/README.md @@ -11,20 +11,39 @@ ## [784. Letter Case Permutation (Medium)](https://leetcode.com/problems/letter-case-permutation "字母大小写全排列") -

      Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.  Return a list of all possible strings we could create.

      +

      Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.

      + +

      Return a list of all possible strings we could create. You can return the output  in any order.

      + +

       

      +

      Example 1:

      -Examples:
       Input: S = "a1b2"
      -Output: ["a1b2", "a1B2", "A1b2", "A1B2"]
      +Output: ["a1b2","a1B2","A1b2","A1B2"]
      +
      +

      Example 2:

      + +
       Input: S = "3z4"
      -Output: ["3z4", "3Z4"]
      +Output: ["3z4","3Z4"]
      +
      +

      Example 3:

      + +
       Input: S = "12345"
       Output: ["12345"]
       
      +

      Example 4:

      + +
      +Input: S = "0"
      +Output: ["0"]
      +
      +

       

      Constraints:

      diff --git a/problems/letter-tile-possibilities/README.md b/problems/letter-tile-possibilities/README.md index 2823e0444..f72cd0874 100644 --- a/problems/letter-tile-possibilities/README.md +++ b/problems/letter-tile-possibilities/README.md @@ -11,35 +11,40 @@ ## [1079. Letter Tile Possibilities (Medium)](https://leetcode.com/problems/letter-tile-possibilities "活字印刷") -

      You have a set of tiles, where each tile has one letter tiles[i] printed on it.  Return the number of possible non-empty sequences of letters you can make.

      +

      You have n  tiles, where each tile has one letter tiles[i] printed on it.

      -

       

      +

      Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.

      +

       

      Example 1:

      -Input: "AAB"
      -Output: 8
      +Input: tiles = "AAB"
      +Output: 8
       Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".
       
      -

      Example 2:

      -Input: "AAABBC"
      -Output: 188
      +Input: tiles = "AAABBC"
      +Output: 188
       
      -

       

      -
      +

      Example 3:

      -

      Note:

      +
      +Input: tiles = "V"
      +Output: 1
      +
      + +

       

      +

      Constraints:

      -
        +
        • 1 <= tiles.length <= 7
        • tiles consists of uppercase English letters.
        • -
      + ### Related Topics [[Backtracking](../../tag/backtracking/README.md)] diff --git a/problems/longest-arithmetic-subsequence-of-given-difference/README.md b/problems/longest-arithmetic-subsequence-of-given-difference/README.md index b56061b0a..5dd08c02d 100644 --- a/problems/longest-arithmetic-subsequence-of-given-difference/README.md +++ b/problems/longest-arithmetic-subsequence-of-given-difference/README.md @@ -5,7 +5,7 @@ -[< Previous](../play-with-chips "Play with Chips") +[< Previous](../minimum-cost-to-move-chips-to-the-same-position "Minimum Cost to Move Chips to The Same Position")                  [Next >](../path-with-maximum-gold "Path with Maximum Gold") diff --git a/problems/longest-arithmetic-subsequence/README.md b/problems/longest-arithmetic-subsequence/README.md new file mode 100644 index 000000000..7d417a079 --- /dev/null +++ b/problems/longest-arithmetic-subsequence/README.md @@ -0,0 +1,55 @@ + + + + + + + +[< Previous](../maximum-difference-between-node-and-ancestor "Maximum Difference Between Node and Ancestor") +                 +[Next >](../recover-a-tree-from-preorder-traversal "Recover a Tree From Preorder Traversal") + +## [1027. Longest Arithmetic Subsequence (Medium)](https://leetcode.com/problems/longest-arithmetic-subsequence "最长等差数列") + +

      Given an array A of integers, return the length of the longest arithmetic subsequence in A.

      + +

      Recall that a subsequence of A is a list A[i_1], A[i_2], ..., A[i_k] with 0 <= i_1 < i_2 < ... < i_k <= A.length - 1, and that a sequence B is arithmetic if B[i+1] - B[i] are all the same value (for 0 <= i < B.length - 1).

      + +

       

      +

      Example 1:

      + +
      +Input: A = [3,6,9,12]
      +Output: 4
      +Explanation: 
      +The whole array is an arithmetic sequence with steps of length = 3.
      +
      + +

      Example 2:

      + +
      +Input: A = [9,4,7,2,10]
      +Output: 3
      +Explanation: 
      +The longest arithmetic subsequence is [4,7,10].
      +
      + +

      Example 3:

      + +
      +Input: A = [20,1,15,3,10,5,8]
      +Output: 4
      +Explanation: 
      +The longest arithmetic subsequence is [20,15,10,5].
      +
      + +

       

      +

      Constraints:

      + +
        +
      • 2 <= A.length <= 1000
      • +
      • 0 <= A[i] <= 500
      • +
      + +### Related Topics + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] diff --git a/problems/magnetic-force-between-two-balls/README.md b/problems/magnetic-force-between-two-balls/README.md new file mode 100644 index 000000000..661e4bb9d --- /dev/null +++ b/problems/magnetic-force-between-two-balls/README.md @@ -0,0 +1,66 @@ + + + + + + + +[< Previous](../minimum-operations-to-make-array-equal "Minimum Operations to Make Array Equal") +                 +[Next >](../minimum-number-of-days-to-eat-n-oranges "Minimum Number of Days to Eat N Oranges") + +## [1552. Magnetic Force Between Two Balls (Medium)](https://leetcode.com/problems/magnetic-force-between-two-balls "两球之间的磁力") + +

      In universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.

      + +

      Rick stated that magnetic force between two different balls at positions x and y is |x - y|.

      + +

      Given the integer array position and the integer m. Return the required force.

      + +

       

      +

      Example 1:

      + +
      +Input: position = [1,2,3,4,7], m = 3
      +Output: 3
      +Explanation: Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.
      +
      + +

      Example 2:

      + +
      +Input: position = [5,4,3,2,1,1000000000], m = 2
      +Output: 999999999
      +Explanation: We can use baskets 1 and 1000000000.
      +
      + +

       

      +

      Constraints:

      + +
        +
      • n == position.length
      • +
      • 2 <= n <= 10^5
      • +
      • 1 <= position[i] <= 10^9
      • +
      • All integers in position are distinct.
      • +
      • 2 <= m <= position.length
      • +
      + +### Related Topics + [[Array](../../tag/array/README.md)] + [[Binary Search](../../tag/binary-search/README.md)] + +### Hints +
      +Hint 1 +If you can place balls such that the answer is x then you can do it for y where y < x. +
      + +
      +Hint 2 +Similarly if you cannot place balls such that the answer is x then you can do it for y where y > x. +
      + +
      +Hint 3 +Binary search on the answer and greedily see if it is possible. +
      diff --git a/problems/maximum-difference-between-node-and-ancestor/README.md b/problems/maximum-difference-between-node-and-ancestor/README.md index 8b2246096..e6468749e 100644 --- a/problems/maximum-difference-between-node-and-ancestor/README.md +++ b/problems/maximum-difference-between-node-and-ancestor/README.md @@ -7,7 +7,7 @@ [< Previous](../divisor-game "Divisor Game")                  -[Next >](../longest-arithmetic-sequence "Longest Arithmetic Sequence") +[Next >](../longest-arithmetic-subsequence "Longest Arithmetic Subsequence") ## [1026. Maximum Difference Between Node and Ancestor (Medium)](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor "节点与其祖先之间的最大差值") diff --git a/problems/merge-k-sorted-lists/README.md b/problems/merge-k-sorted-lists/README.md index 28fc7a4fc..eca2c3623 100644 --- a/problems/merge-k-sorted-lists/README.md +++ b/problems/merge-k-sorted-lists/README.md @@ -9,22 +9,54 @@                  [Next >](../swap-nodes-in-pairs "Swap Nodes in Pairs") -## [23. Merge k Sorted Lists (Hard)](https://leetcode.com/problems/merge-k-sorted-lists "合并K个排序链表") +## [23. Merge k Sorted Lists (Hard)](https://leetcode.com/problems/merge-k-sorted-lists "合并K个升序链表") -

      Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

      +

      Given an array of linked-lists lists, each linked list is sorted in ascending order.

      -

      Example:

      +

      Merge all the linked-lists into one sort linked-list and return it.

      + +

       

      +

      Example 1:

      -Input:
      +Input: lists = [[1,4,5],[1,3,4],[2,6]]
      +Output: [1,1,2,3,4,4,5,6]
      +Explanation: The linked-lists are:
       [
      -  1->4->5,
      -  1->3->4,
      -  2->6
      +  1->4->5,
      +  1->3->4,
      +  2->6
       ]
      -Output: 1->1->2->3->4->4->5->6
      +merging them into one sorted list:
      +1->1->2->3->4->4->5->6
      +
      + +

      Example 2:

      + +
      +Input: lists = []
      +Output: []
       
      +

      Example 3:

      + +
      +Input: lists = [[]]
      +Output: []
      +
      + +

       

      +

      Constraints:

      + +
        +
      • k == lists.length
      • +
      • 0 <= k <= 10^4
      • +
      • 0 <= lists[i].length <= 500
      • +
      • -10^4 <= lists[i][j] <= 10^4
      • +
      • lists[i] is sorted in ascending order.
      • +
      • The sum of lists[i].length won't exceed 10^4.
      • +
      + ### Related Topics [[Heap](../../tag/heap/README.md)] [[Linked List](../../tag/linked-list/README.md)] diff --git a/problems/minimum-cost-to-cut-a-stick/README.md b/problems/minimum-cost-to-cut-a-stick/README.md index 87c37b87c..fee9eddb9 100644 --- a/problems/minimum-cost-to-cut-a-stick/README.md +++ b/problems/minimum-cost-to-cut-a-stick/README.md @@ -7,7 +7,7 @@ [< Previous](../maximum-number-of-non-overlapping-subarrays-with-sum-equals-target "Maximum Number of Non-Overlapping Subarrays With Sum Equals Target")                  -Next > +[Next >](../the-most-similar-path-in-a-graph "The Most Similar Path in a Graph") ## [1547. Minimum Cost to Cut a Stick (Hard)](https://leetcode.com/problems/minimum-cost-to-cut-a-stick "切棍子的最小成本") diff --git a/problems/minimum-cost-to-move-chips-to-the-same-position/README.md b/problems/minimum-cost-to-move-chips-to-the-same-position/README.md new file mode 100644 index 000000000..100a49005 --- /dev/null +++ b/problems/minimum-cost-to-move-chips-to-the-same-position/README.md @@ -0,0 +1,83 @@ + + + + + + + +[< Previous](../valid-palindrome-iii "Valid Palindrome III") +                 +[Next >](../longest-arithmetic-subsequence-of-given-difference "Longest Arithmetic Subsequence of Given Difference") + +## [1217. Minimum Cost to Move Chips to The Same Position (Easy)](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position "玩筹码") + +

      We have n chips, where the position of the ith chip is position[i].

      + +

      We need to move all the chips to the same position, In one step, we can change the position of the ith chip from position[i] to:

      + +
        +
      • position[i] + 2 or position[i] - 2 with cost = 0.
      • +
      • position[i] + 1 or position[i] - 1 with cost = 1.
      • +
      + +

      Return the minimum cost needed to move all the chips to the same position.

      + +

       

      +

      Example 1:

      + +
      +Input: position = [1,2,3]
      +Output: 1
      +Explanation: First step: Move the chip at position 3 to position 1 with cost = 0.
      +Second step: Move the chip at position 2 to position 1 with cost = 1.
      +Total cost is 1.
      +
      + +

      Example 2:

      + +
      +Input: position = [2,2,2,3,3]
      +Output: 2
      +Explanation: We can move the two chips at poistion 3 to position 2. Each move has cost = 1. The total cost = 2.
      +
      + +

      Example 3:

      + +
      +Input: position = [1,1000000000]
      +Output: 1
      +
      + +

       

      +

      Constraints:

      + +
        +
      • 1 <= position.length <= 100
      • +
      • 1 <= position[i] <= 10^9
      • +
      + +### Related Topics + [[Greedy](../../tag/greedy/README.md)] + [[Array](../../tag/array/README.md)] + [[Math](../../tag/math/README.md)] + +### Hints +
      +Hint 1 +The first move keeps the parity of the element as it is. +
      + +
      +Hint 2 +The second move changes the parity of the element. +
      + +
      +Hint 3 +Since the first move is free, if all the numbers have the same parity, the answer would be zero. +
      + +
      +Hint 4 +Find the minimum cost to make all the numbers have the same parity. +
      diff --git a/problems/minimum-insertions-to-balance-a-parentheses-string/README.md b/problems/minimum-insertions-to-balance-a-parentheses-string/README.md index 369fd2f3a..5a740a59e 100644 --- a/problems/minimum-insertions-to-balance-a-parentheses-string/README.md +++ b/problems/minimum-insertions-to-balance-a-parentheses-string/README.md @@ -18,9 +18,11 @@
    1. Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.
    2. +

      In other words, we treat '(' as openning parenthesis and '))' as closing parenthesis.

      +

      For example, "())", "())(())))" and "(())())))" are balanced, ")()", "()))" and "(()))" are not balanced.

      -

      You can insert the characters '(' and ')' at any position of the string to balance it if needed.

      +

      You can insert the characters '(' and ')' at any position of the string to balance it if needed.

      Return the minimum number of insertions needed to make s balanced.

      diff --git a/problems/minimum-number-of-days-to-eat-n-oranges/README.md b/problems/minimum-number-of-days-to-eat-n-oranges/README.md new file mode 100644 index 000000000..3229bcebf --- /dev/null +++ b/problems/minimum-number-of-days-to-eat-n-oranges/README.md @@ -0,0 +1,82 @@ + + + + + + + +[< Previous](../magnetic-force-between-two-balls "Magnetic Force Between Two Balls") +                 +Next > + +## [1553. Minimum Number of Days to Eat N Oranges (Hard)](https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges "吃掉 N 个橘子的最少天数") + +

      There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:

      + +
        +
      • Eat one orange.
      • +
      • If the number of remaining oranges (n) is divisible by 2 then you can eat  n/2 oranges.
      • +
      • If the number of remaining oranges (n) is divisible by 3 then you can eat  2*(n/3) oranges.
      • +
      + +

      You can only choose one of the actions per day.

      + +

      Return the minimum number of days to eat n oranges.

      + +

       

      +

      Example 1:

      + +
      +Input: n = 10
      +Output: 4
      +Explanation: You have 10 oranges.
      +Day 1: Eat 1 orange,  10 - 1 = 9.  
      +Day 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)
      +Day 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. 
      +Day 4: Eat the last orange  1 - 1  = 0.
      +You need at least 4 days to eat the 10 oranges.
      +
      + +

      Example 2:

      + +
      +Input: n = 6
      +Output: 3
      +Explanation: You have 6 oranges.
      +Day 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).
      +Day 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)
      +Day 3: Eat the last orange  1 - 1  = 0.
      +You need at least 3 days to eat the 6 oranges.
      +
      + +

      Example 3:

      + +
      +Input: n = 1
      +Output: 1
      +
      + +

      Example 4:

      + +
      +Input: n = 56
      +Output: 6
      +
      + +

       

      +

      Constraints:

      + +
        +
      • 1 <= n <= 2*10^9
      • +
      + +### Related Topics + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
      +Hint 1 +In each step, choose between 2 options: +minOranges = 1 + min( (n%2) + f(n/2), (n%3) + f(n/3) ) +where f(n) is the minimum number of days to eat n oranges. +
      diff --git a/problems/minimum-operations-to-make-array-equal/README.md b/problems/minimum-operations-to-make-array-equal/README.md new file mode 100644 index 000000000..a975cb28b --- /dev/null +++ b/problems/minimum-operations-to-make-array-equal/README.md @@ -0,0 +1,57 @@ + + + + + + + +[< Previous](../three-consecutive-odds "Three Consecutive Odds") +                 +[Next >](../magnetic-force-between-two-balls "Magnetic Force Between Two Balls") + +## [1551. Minimum Operations to Make Array Equal (Medium)](https://leetcode.com/problems/minimum-operations-to-make-array-equal "使数组中所有元素相等的最小操作数") + +

      You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n).

      + +

      In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e. perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is guaranteed that all the elements of the array can be made equal using some operations.

      + +

      Given an integer n, the length of the array. Return the minimum number of operations needed to make all the elements of arr equal.

      + +

       

      +

      Example 1:

      + +
      +Input: n = 3
      +Output: 2
      +Explanation: arr = [1, 3, 5]
      +First operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]
      +In the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].
      +
      + +

      Example 2:

      + +
      +Input: n = 6
      +Output: 9
      +
      + +

       

      +

      Constraints:

      + +
        +
      • 1 <= n <= 10^4
      • +
      + +### Related Topics + [[Math](../../tag/math/README.md)] + +### Hints +
      +Hint 1 +Build the array arr using the given formula, define target = sum(arr) / n +
      + +
      +Hint 2 +What is the number of operations needed to convert arr so that all elements equal target ? +
      diff --git a/problems/move-sub-tree-of-n-ary-tree/README.md b/problems/move-sub-tree-of-n-ary-tree/README.md index 2451c61bf..9e0e67911 100644 --- a/problems/move-sub-tree-of-n-ary-tree/README.md +++ b/problems/move-sub-tree-of-n-ary-tree/README.md @@ -9,7 +9,7 @@                  [Next >](../find-users-with-valid-e-mails "Find Users With Valid E-Mails") -## [1516. Move Sub-Tree of N-Ary Tree (Hard)](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree "") +## [1516. Move Sub-Tree of N-Ary Tree (Hard)](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree "移动 N 叉树的子树") diff --git a/problems/number-of-submatrices-that-sum-to-target/README.md b/problems/number-of-submatrices-that-sum-to-target/README.md index 64a0cf50b..14b4947e0 100644 --- a/problems/number-of-submatrices-that-sum-to-target/README.md +++ b/problems/number-of-submatrices-that-sum-to-target/README.md @@ -48,6 +48,16 @@
    3. -10^8 <= target <= 10^8
    +

     

    +

    Constraints:

    + + + ### Related Topics [[Array](../../tag/array/README.md)] [[Dynamic Programming](../../tag/dynamic-programming/README.md)] diff --git a/problems/open-the-lock/README.md b/problems/open-the-lock/README.md index 94e887a81..fd1e13cea 100644 --- a/problems/open-the-lock/README.md +++ b/problems/open-the-lock/README.md @@ -11,59 +11,61 @@ ## [752. Open the Lock (Medium)](https://leetcode.com/problems/open-the-lock "打开转盘锁") -

    -You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot. -

    -The lock initially starts at '0000', a string representing the state of the 4 wheels. -

    -You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it. -

    -Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible. -

    - -

    Example 1:
    +

    You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot.

    + +

    The lock initially starts at '0000', a string representing the state of the 4 wheels.

    + +

    You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it.

    + +

    Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.

    + +

     

    +

    Example 1:

    +
    -Input: deadends = ["0201","0101","0102","1212","2002"], target = "0202"
    -Output: 6
    -Explanation:
    -A sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".
    -Note that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,
    -because the wheels of the lock become stuck after the display becomes the dead end "0102".
    +Input: deadends = ["0201","0101","0102","1212","2002"], target = "0202"
    +Output: 6
    +Explanation:
    +A sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".
    +Note that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,
    +because the wheels of the lock become stuck after the display becomes the dead end "0102".
     
    -

    -

    Example 2:
    +

    Example 2:

    +
    -Input: deadends = ["8888"], target = "0009"
    -Output: 1
    -Explanation:
    -We can turn the last wheel in reverse to move from "0000" -> "0009".
    +Input: deadends = ["8888"], target = "0009"
    +Output: 1
    +Explanation:
    +We can turn the last wheel in reverse to move from "0000" -> "0009".
     
    -

    -

    Example 3:
    +

    Example 3:

    +
    -Input: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"
    -Output: -1
    -Explanation:
    -We can't reach the target without getting stuck.
    +Input: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"
    +Output: -1
    +Explanation:
    +We can't reach the target without getting stuck.
     
    -

    -

    Example 4:
    +

    Example 4:

    +
    -Input: deadends = ["0000"], target = "8888"
    -Output: -1
    +Input: deadends = ["0000"], target = "8888"
    +Output: -1
     
    -

    - -

    Note:
    -

      -
    1. The length of deadends will be in the range [1, 500].
    2. -
    3. target will not be in the list deadends.
    4. -
    5. Every string in deadends and the string target will be a string of 4 digits from the 10,000 possibilities '0000' to '9999'.
    6. -
    -

    + +

     

    +

    Constraints:

    + + ### Related Topics [[Breadth-first Search](../../tag/breadth-first-search/README.md)] diff --git a/problems/palindrome-partitioning-ii/README.md b/problems/palindrome-partitioning-ii/README.md index f511bd3c9..9f1832987 100644 --- a/problems/palindrome-partitioning-ii/README.md +++ b/problems/palindrome-partitioning-ii/README.md @@ -11,18 +11,41 @@ ## [132. Palindrome Partitioning II (Hard)](https://leetcode.com/problems/palindrome-partitioning-ii "分割回文串 II") -

    Given a string s, partition s such that every substring of the partition is a palindrome.

    +

    Given a string s, partition s such that every substring of the partition is a palindrome

    -

    Return the minimum cuts needed for a palindrome partitioning of s.

    +

    Return the minimum cuts needed for a palindrome partitioning of s.

    -

    Example:

    +

     

    +

    Example 1:

    -Input: "aab"
    +Input: s = "aab"
     Output: 1
     Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
     
    +

    Example 2:

    + +
    +Input: s = "a"
    +Output: 0
    +
    + +

    Example 3:

    + +
    +Input: s = "ab"
    +Output: 1
    +
    + +

     

    +

    Constraints:

    + + + ### Related Topics [[Dynamic Programming](../../tag/dynamic-programming/README.md)] diff --git a/problems/pancake-sorting/README.md b/problems/pancake-sorting/README.md index 7c0d1e180..2e2bd5f39 100644 --- a/problems/pancake-sorting/README.md +++ b/problems/pancake-sorting/README.md @@ -11,45 +11,52 @@ ## [969. Pancake Sorting (Medium)](https://leetcode.com/problems/pancake-sorting "煎饼排序") -

    Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, then reverse the order of the first k elements of A.  We want to perform zero or more pancake flips (doing them one after another in succession) to sort the array A.

    +

    Given an array of integers A, We need to sort the array performing a series of pancake flips.

    -

    Return the k-values corresponding to a sequence of pancake flips that sort A.  Any valid answer that sorts the array within 10 * A.length flips will be judged as correct.

    +

    In one pancake flip we do the following steps:

    -

     

    + + +

    For example, if A = [3,2,1,4] and we performed a pancake flip choosing k = 2, we reverse the sub-array [3,2,1], so A = [1,2,3,4] after the pancake flip at k = 2.

    + +

    Return an array of the k-values of the pancake flips that should be performed in order to sort A. Any valid answer that sorts the array within 10 * A.length flips will be judged as correct.

    +

     

    Example 1:

    -Input: [3,2,4,1]
    -Output: [4,2,4,3]
    +Input: A = [3,2,4,1]
    +Output: [4,2,4,3]
     Explanation: 
     We perform 4 pancake flips, with k values 4, 2, 4, and 3.
     Starting state: A = [3, 2, 4, 1]
    -After 1st flip (k=4): A = [1, 4, 2, 3]
    -After 2nd flip (k=2): A = [4, 1, 2, 3]
    -After 3rd flip (k=4): A = [3, 2, 1, 4]
    -After 4th flip (k=3): A = [1, 2, 3, 4], which is sorted. 
    +After 1st flip (k = 4): A = [1, 4, 2, 3]
    +After 2nd flip (k = 2): A = [4, 1, 2, 3]
    +After 3rd flip (k = 4): A = [3, 2, 1, 4]
    +After 4th flip (k = 3): A = [1, 2, 3, 4], which is sorted.
    +Notice that we return an array of the chosen k values of the pancake flips.
     
    -

    Example 2:

    -Input: [1,2,3]
    -Output: []
    +Input: A = [1,2,3]
    +Output: []
     Explanation: The input is already sorted, so there is no need to flip anything.
     Note that other answers, such as [3, 3], would also be accepted.
     

     

    -
    - -

    Note:

    +

    Constraints:

    -
      +
      • 1 <= A.length <= 100
      • -
      • A[i] is a permutation of [1, 2, ..., A.length]
      • -
    +
  5. 1 <= A[i] <= A.length
  6. +
  7. All integers in A are unique (i.e. A is a permutation of the integers from 1 to A.length).
  8. + ### Related Topics [[Sort](../../tag/sort/README.md)] diff --git a/problems/prefix-and-suffix-search/README.md b/problems/prefix-and-suffix-search/README.md index f7fb85160..321939389 100644 --- a/problems/prefix-and-suffix-search/README.md +++ b/problems/prefix-and-suffix-search/README.md @@ -42,7 +42,7 @@ WordFilter.f("b", "") // returns -1 [[Trie](../../tag/trie/README.md)] ### Similar Questions - 1. [Add and Search Word - Data structure design](../add-and-search-word-data-structure-design) (Medium) + 1. [Design Add and Search Words Data Structure](../design-add-and-search-words-data-structure) (Medium) ### Hints
    diff --git a/problems/profitable-schemes/README.md b/problems/profitable-schemes/README.md index 91e524a43..7e3d68adc 100644 --- a/problems/profitable-schemes/README.md +++ b/problems/profitable-schemes/README.md @@ -11,13 +11,13 @@ ## [879. Profitable Schemes (Hard)](https://leetcode.com/problems/profitable-schemes "盈利计划") -

    There are G people in a gang, and a list of various crimes they could commit.

    +

    There is a group of G members, and a list of various crimes they could commit.

    -

    The i-th crime generates a profit[i] and requires group[i] gang members to participate.

    +

    The ith crime generates a profit[i] and requires group[i] members to participate in it.

    -

    If a gang member participates in one crime, that member can't participate in another crime.

    +

    If a member participates in one crime, that member can't participate in another crime.

    -

    Let's call a profitable scheme any subset of these crimes that generates at least P profit, and the total number of gang members participating in that subset of crimes is at most G.

    +

    Let's call a profitable scheme any subset of these crimes that generates at least P profit, and the total number of members participating in that subset of crimes is at most G.

    How many schemes can be chosen?  Since the answer may be very large, return it modulo 10^9 + 7.

    @@ -29,7 +29,7 @@ Input: G = 5, P = 3, group = [2,2], profit = [2,3] Output: 2 Explanation: -To make a profit of at least 3, the gang could either commit crimes 0 and 1, or just crime 1. +To make a profit of at least 3, the group could either commit crimes 0 and 1, or just crime 1. In total, there are 2 schemes. @@ -40,7 +40,7 @@ In total, there are 2 schemes. Input: G = 10, P = 5, group = [2,3,5], profit = [6,7,8] Output: 7 Explanation: -To make a profit of at least 5, the gang could commit any crimes, as long as they commit one. +To make a profit of at least 5, the group could commit any crimes, as long as they commit one. There are 7 possible schemes: (0), (1), (2), (0,1), (0,2), (1,2), and (0,1,2). diff --git a/problems/random-pick-with-weight/README.md b/problems/random-pick-with-weight/README.md index 79ff5c5bf..c6caa1433 100644 --- a/problems/random-pick-with-weight/README.md +++ b/problems/random-pick-with-weight/README.md @@ -11,9 +11,11 @@ ## [528. Random Pick with Weight (Medium)](https://leetcode.com/problems/random-pick-with-weight "按权重随机选择") -

    Given an array w of positive integers, where w[i] describes the weight of index i(0-indexed), write a function pickIndex which randomly picks an index in proportion to its weight.

    +

    Given an array of positive integers w. where w[i] describes the weight of ith index (0-indexed).

    -

    For example, given an input list of values w = [2, 8], when we pick up a number out of it, the chance is that 8 times out of 10 we should pick the number 1 as the answer since it's the second element of the array (w[1] = 8).

    +

    We need to call the function pickIndex() which randomly returns an integer in the range [0, w.length - 1]pickIndex() should return the integer proportional to its weight in the w array. For example, for w = [1, 3], the probability of picking index 0 is 1 / (1 + 3) = 0.25 (i.e 25%) while the probability of picking index 1 is 3 / (1 + 3) = 0.75 (i.e 75%).

    + +

    More formally, the probability of picking index i is w[i] / sum(w).

     

    Example 1:

    diff --git a/problems/recover-a-tree-from-preorder-traversal/README.md b/problems/recover-a-tree-from-preorder-traversal/README.md index f76b12e26..44eddb124 100644 --- a/problems/recover-a-tree-from-preorder-traversal/README.md +++ b/problems/recover-a-tree-from-preorder-traversal/README.md @@ -5,7 +5,7 @@ -[< Previous](../longest-arithmetic-sequence "Longest Arithmetic Sequence") +[< Previous](../longest-arithmetic-subsequence "Longest Arithmetic Subsequence")                  [Next >](../two-city-scheduling "Two City Scheduling") diff --git a/problems/restore-ip-addresses/README.md b/problems/restore-ip-addresses/README.md index 7f44a6fd7..7f562fce0 100644 --- a/problems/restore-ip-addresses/README.md +++ b/problems/restore-ip-addresses/README.md @@ -11,16 +11,34 @@ ## [93. Restore IP Addresses (Medium)](https://leetcode.com/problems/restore-ip-addresses "复原IP地址") -

    Given a string containing only digits, restore it by returning all possible valid IP address combinations.

    - -

    A valid IP address consists of exactly four integers (each integer is between 0 and 255) separated by single points.

    - -

    Example:

    - -
    -Input: "25525511135"
    -Output: ["255.255.11.135", "255.255.111.35"]
    -
    +

    Given a string s containing only digits. Return all possible valid IP addresses that can be obtained from s. You can return them in any order.

    + +

    A valid IP address consists of exactly four integers, each integer is between 0 and 255, separated by single points and cannot have leading zeros. For example, "0.1.2.201" and "192.168.1.1" are valid IP addresses and "0.011.255.245", "192.168.1.312" and "192.168@1.1" are invalid IP addresses. 

    + +

     

    +

    Example 1:

    +
    Input: s = "25525511135"
    +Output: ["255.255.11.135","255.255.111.35"]
    +

    Example 2:

    +
    Input: s = "0000"
    +Output: ["0.0.0.0"]
    +

    Example 3:

    +
    Input: s = "1111"
    +Output: ["1.1.1.1"]
    +

    Example 4:

    +
    Input: s = "010010"
    +Output: ["0.10.0.10","0.100.1.0"]
    +

    Example 5:

    +
    Input: s = "101023"
    +Output: ["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
    +
    +

     

    +

    Constraints:

    + +
      +
    • 0 <= s.length <= 3000
    • +
    • s consists of digits only.
    • +
    ### Related Topics [[String](../../tag/string/README.md)] diff --git a/problems/search-in-rotated-sorted-array/README.md b/problems/search-in-rotated-sorted-array/README.md index 84e319757..48b8d6919 100644 --- a/problems/search-in-rotated-sorted-array/README.md +++ b/problems/search-in-rotated-sorted-array/README.md @@ -11,28 +11,33 @@ ## [33. Search in Rotated Sorted Array (Medium)](https://leetcode.com/problems/search-in-rotated-sorted-array "搜索旋转排序数组") -

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

    +

    Given an integer array nums sorted in ascending order, and an integer target.

    -

    (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

    +

    Suppose that nums is rotated at some pivot unknown to you beforehand (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

    -

    You are given a target value to search. If found in the array return its index, otherwise return -1.

    - -

    You may assume no duplicate exists in the array.

    - -

    Your algorithm's runtime complexity must be in the order of O(log n).

    +

    You should search for target in nums and if you found return its index, otherwise return -1.

    +

     

    Example 1:

    - -
    -Input: nums = [4,5,6,7,0,1,2], target = 0
    +
    Input: nums = [4,5,6,7,0,1,2], target = 0
     Output: 4
    +

    Example 2:

    +
    Input: nums = [4,5,6,7,0,1,2], target = 3
    +Output: -1
    +

    Example 3:

    +
    Input: nums = [1], target = 0
    +Output: -1
     
    - -

    Example 2:

    - -
    -Input: nums = [4,5,6,7,0,1,2], target = 3
    -Output: -1
    +

     

    +

    Constraints:

    + +
      +
    • 1 <= nums.length <= 5000
    • +
    • -10^4 <= nums[i] <= 10^4
    • +
    • All values of nums are unique.
    • +
    • nums is guranteed to be rotated at some pivot.
    • +
    • -10^4 <= target <= 10^4
    • +
    ### Related Topics [[Array](../../tag/array/README.md)] diff --git a/problems/set-intersection-size-at-least-two/README.md b/problems/set-intersection-size-at-least-two/README.md index 1e96a4568..55fab50bc 100644 --- a/problems/set-intersection-size-at-least-two/README.md +++ b/problems/set-intersection-size-at-least-two/README.md @@ -9,7 +9,7 @@                  [Next >](../bold-words-in-string "Bold Words in String") -## [757. Set Intersection Size At Least Two (Hard)](https://leetcode.com/problems/set-intersection-size-at-least-two " 设置交集大小至少为2") +## [757. Set Intersection Size At Least Two (Hard)](https://leetcode.com/problems/set-intersection-size-at-least-two "设置交集大小至少为2")

    An integer interval [a, b] (for integers a < b) is a set of all consecutive integers from a to b, including a and b. diff --git a/problems/stone-game/README.md b/problems/stone-game/README.md index b0760bc1b..3ed729a0e 100644 --- a/problems/stone-game/README.md +++ b/problems/stone-game/README.md @@ -20,12 +20,11 @@

    Assuming Alex and Lee play optimally, return True if and only if Alex wins the game.

     

    -

    Example 1:

    -Input: [5,3,4,5]
    -Output: true
    +Input: piles = [5,3,4,5]
    +Output: true
     Explanation: 
     Alex starts first, and can only take the first 5 or the last 5.
     Say he takes the first 5, so that the row becomes [3, 4, 5].
    @@ -35,15 +34,14 @@ This demonstrated that taking the first 5 was a winning move for Alex, so we ret
     

     

    +

    Constraints:

    -

    Note:

    - -
      +
      • 2 <= piles.length <= 500
      • piles.length is even.
      • 1 <= piles[i] <= 500
      • sum(piles) is odd.
      • -
    + ### Related Topics [[Minimax](../../tag/minimax/README.md)] diff --git a/problems/the-most-recent-orders-for-each-product/README.md b/problems/the-most-recent-orders-for-each-product/README.md new file mode 100644 index 000000000..812900ece --- /dev/null +++ b/problems/the-most-recent-orders-for-each-product/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](../the-most-similar-path-in-a-graph "The Most Similar Path in a Graph") +                 +[Next >](../three-consecutive-odds "Three Consecutive Odds") + +## [1549. The Most Recent Orders for Each Product (Medium)](https://leetcode.com/problems/the-most-recent-orders-for-each-product "") + + diff --git a/problems/the-most-recent-orders-for-each-product/mysql_schemas.sql b/problems/the-most-recent-orders-for-each-product/mysql_schemas.sql new file mode 100644 index 000000000..7da4f47bc --- /dev/null +++ b/problems/the-most-recent-orders-for-each-product/mysql_schemas.sql @@ -0,0 +1,25 @@ +Create table If Not Exists Customers (customer_id int, name varchar(10)); +Create table If Not Exists Orders (order_id int, order_date date, customer_id int, product_id int); +Create table If Not Exists Products (product_id int, product_name varchar(20), price int); +Truncate table Customers; +insert into Customers (customer_id, name) values ('1', 'Winston'); +insert into Customers (customer_id, name) values ('2', 'Jonathan'); +insert into Customers (customer_id, name) values ('3', 'Annabelle'); +insert into Customers (customer_id, name) values ('4', 'Marwan'); +insert into Customers (customer_id, name) values ('5', 'Khaled'); +Truncate table Orders; +insert into Orders (order_id, order_date, customer_id, product_id) values ('1', '2020-07-31', '1', '1'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('2', '2020-7-30', '2', '2'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('3', '2020-08-29', '3', '3'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('4', '2020-07-29', '4', '1'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('5', '2020-06-10', '1', '2'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('6', '2020-08-01', '2', '1'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('7', '2020-08-01', '3', '1'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('8', '2020-08-03', '1', '2'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('9', '2020-08-07', '2', '3'); +insert into Orders (order_id, order_date, customer_id, product_id) values ('10', '2020-07-15', '1', '2'); +Truncate table Products; +insert into Products (product_id, product_name, price) values ('1', 'keyboard', '120'); +insert into Products (product_id, product_name, price) values ('2', 'mouse', '80'); +insert into Products (product_id, product_name, price) values ('3', 'screen', '600'); +insert into Products (product_id, product_name, price) values ('4', 'hard disk', '450'); diff --git a/problems/the-most-similar-path-in-a-graph/README.md b/problems/the-most-similar-path-in-a-graph/README.md new file mode 100644 index 000000000..7d17a5781 --- /dev/null +++ b/problems/the-most-similar-path-in-a-graph/README.md @@ -0,0 +1,29 @@ + + + + + + + +[< Previous](../minimum-cost-to-cut-a-stick "Minimum Cost to Cut a Stick") +                 +[Next >](../the-most-recent-orders-for-each-product "The Most Recent Orders for Each Product") + +## [1548. The Most Similar Path in a Graph (Hard)](https://leetcode.com/problems/the-most-similar-path-in-a-graph "") + + + +### Related Topics + [[Graph](../../tag/graph/README.md)] + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
    +Hint 1 +Create an array dp where dp[i][j] is the min edit distance for the path starting at node i and compared to index j of the targetPath. +
    + +
    +Hint 2 +Traverse the dp array to obtain a valid answer. +
    diff --git a/problems/three-consecutive-odds/README.md b/problems/three-consecutive-odds/README.md new file mode 100644 index 000000000..89b1e53d8 --- /dev/null +++ b/problems/three-consecutive-odds/README.md @@ -0,0 +1,47 @@ + + + + + + + +[< Previous](../the-most-recent-orders-for-each-product "The Most Recent Orders for Each Product") +                 +[Next >](../minimum-operations-to-make-array-equal "Minimum Operations to Make Array Equal") + +## [1550. Three Consecutive Odds (Easy)](https://leetcode.com/problems/three-consecutive-odds "存在连续三个奇数的数组") + +Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false. +

     

    +

    Example 1:

    + +
    +Input: arr = [2,6,4,1]
    +Output: false
    +Explanation: There are no three consecutive odds.
    +
    + +

    Example 2:

    + +
    +Input: arr = [1,2,34,3,4,5,7,23,12]
    +Output: true
    +Explanation: [5,7,23] are three consecutive odds.
    +
    + +

     

    +

    Constraints:

    + +
      +
    • 1 <= arr.length <= 1000
    • +
    • 1 <= arr[i] <= 1000
    • +
    + +### Related Topics + [[Array](../../tag/array/README.md)] + +### Hints +
    +Hint 1 +Check every three consecutive numbers in the array for parity. +
    diff --git a/problems/valid-palindrome-iii/README.md b/problems/valid-palindrome-iii/README.md index d6521343f..b9c826790 100644 --- a/problems/valid-palindrome-iii/README.md +++ b/problems/valid-palindrome-iii/README.md @@ -7,7 +7,7 @@ [< Previous](../stepping-numbers "Stepping Numbers")                  -[Next >](../play-with-chips "Play with Chips") +[Next >](../minimum-cost-to-move-chips-to-the-same-position "Minimum Cost to Move Chips to The Same Position") ## [1216. Valid Palindrome III (Hard)](https://leetcode.com/problems/valid-palindrome-iii "验证回文字符串 III") diff --git a/problems/validate-ip-address/README.md b/problems/validate-ip-address/README.md index 109142b53..6fed36f31 100644 --- a/problems/validate-ip-address/README.md +++ b/problems/validate-ip-address/README.md @@ -11,17 +11,21 @@ ## [468. Validate IP Address (Medium)](https://leetcode.com/problems/validate-ip-address "验证IP地址") -

    Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither.

    +

    Given a string IP. We need to check If IP is a valid IPv4 address, valid IPv6 address or not a valid IP address.

    -

    IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots ("."), e.g.,172.16.254.1;

    +

    Return "IPv4" if IP is a valid IPv4 address, "IPv6" if IP is a valid IPv6 address or "Neither" if IP is not a valid IP of any type.

    -

    Besides, leading zeros in the IPv4 is invalid. For example, the address 172.16.254.01 is invalid.

    +

    A valid IPv4 address is an IP in the form "x1.x2.x3.x4" where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, "192.168.1.1" and "192.168.1.0" are valid IPv4 addresses but "192.168.01.1", "192.168.1.00" and "192.168@1.1" are invalid IPv4 adresses.

    -

    IPv6 addresses are represented as eight groups of four hexadecimal digits, each group representing 16 bits. The groups are separated by colons (":"). For example, the address 2001:0db8:85a3:0000:0000:8a2e:0370:7334 is a valid one. Also, we could omit some leading zeros among four hexadecimal digits and some low-case characters in the address to upper-case ones, so 2001:db8:85a3:0:0:8A2E:0370:7334 is also a valid IPv6 address(Omit leading zeros and using upper cases).

    +

    A valid IPv6 address is an IP in the form "x1:x2:x3:x4:x5:x6:x7:x8" where:

    -

    However, we don't replace a consecutive group of zero value with a single empty group using two consecutive colons (::) to pursue simplicity. For example, 2001:0db8:85a3::8A2E:0370:7334 is an invalid IPv6 address.

    +
      +
    • 1 <= xi.length <= 4
    • +
    • xi is hexadecimal string whcih may contain digits, lower-case English letter ('a' to 'f') and/or upper-case English letters ('A' to 'F').
    • +
    • Leading zeros are allowed in xi.
    • +
    -

    Besides, extra leading zeros in the IPv6 is also invalid. For example, the address 02001:0db8:85a3:0000:0000:8a2e:0370:7334 is invalid.

    +

    For example, "2001:0db8:85a3:0000:0000:8a2e:0370:7334" and "2001:db8:85a3:0:0:8A2E:0370:7334" are valid IPv6 addresses but "2001:0db8:85a3::8A2E:037j:7334" and "02001:0db8:85a3:0000:0000:8a2e:0370:7334" are invalid IPv6 addresses.

     

    Example 1:

    @@ -48,11 +52,25 @@ Explanation: This is neither a IPv4 address nor a IPv6 address.
    +

    Example 4:

    + +
    +Input: IP = "2001:0db8:85a3:0:0:8A2E:0370:7334:"
    +Output: "Neither"
    +
    + +

    Example 5:

    + +
    +Input: IP = "1e1.4.5.6"
    +Output: "Neither"
    +
    +

     

    Constraints:

      -
    • IP consists only of English letters, digits and the characters "." and ":".
    • +
    • IP consists only of English letters, digits and the characters '.' and ':'.
    ### Related Topics diff --git a/problems/word-search-ii/README.md b/problems/word-search-ii/README.md index 0a51d3e59..959bcf2b8 100644 --- a/problems/word-search-ii/README.md +++ b/problems/word-search-ii/README.md @@ -5,7 +5,7 @@ -[< Previous](../add-and-search-word-data-structure-design "Add and Search Word - Data structure design") +[< Previous](../design-add-and-search-words-data-structure "Design Add and Search Words Data Structure")                  [Next >](../house-robber-ii "House Robber II") diff --git a/readme/1-300.md b/readme/1-300.md index 3c358fe50..8d008f9fe 100644 --- a/readme/1-300.md +++ b/readme/1-300.md @@ -92,7 +92,7 @@ LeetCode Problems' Solutions | 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses "有效的括号") | [Go](../problems/valid-parentheses) | Easy | | 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists "合并两个有序链表") | [Go](../problems/merge-two-sorted-lists) | Easy | | 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses "括号生成") | [Go](../problems/generate-parentheses) | Medium | -| 23 | [Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists "合并K个排序链表") | [Go](../problems/merge-k-sorted-lists) | Hard | +| 23 | [Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists "合并K个升序链表") | [Go](../problems/merge-k-sorted-lists) | Hard | | 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs "两两交换链表中的节点") | [Go](../problems/swap-nodes-in-pairs) | Medium | | 25 | [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group "K 个一组翻转链表") | [Go](../problems/reverse-nodes-in-k-group) | Hard | | 26 | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array "删除排序数组中的重复项") | [Go](../problems/remove-duplicates-from-sorted-array) | Easy | @@ -280,7 +280,7 @@ LeetCode Problems' Solutions | 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree "实现 Trie (前缀树)") | [Go](../problems/implement-trie-prefix-tree) | Medium | | 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum "长度最小的子数组") | [Go](../problems/minimum-size-subarray-sum) | Medium | | 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii "课程表 II") | [Go](../problems/course-schedule-ii) | Medium | -| 211 | [Add and Search Word - Data structure design](https://leetcode.com/problems/add-and-search-word-data-structure-design "添加与搜索单词 - 数据结构设计") | [Go](../problems/add-and-search-word-data-structure-design) | Medium | +| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure "添加与搜索单词 - 数据结构设计") | [Go](../problems/design-add-and-search-words-data-structure) | Medium | | 212 | [Word Search II](https://leetcode.com/problems/word-search-ii "单词搜索 II") | [Go](../problems/word-search-ii) | Hard | | 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii "打家劫舍 II") | [Go](../problems/house-robber-ii) | Medium | | 214 | [Shortest Palindrome](https://leetcode.com/problems/shortest-palindrome "最短回文串") | [Go](../problems/shortest-palindrome) | Hard | diff --git a/readme/601-900.md b/readme/601-900.md index 6d447983a..5c655eb70 100644 --- a/readme/601-900.md +++ b/readme/601-900.md @@ -226,7 +226,7 @@ LeetCode Problems' Solutions | 754 | [Reach a Number](https://leetcode.com/problems/reach-a-number "到达终点数字") | [Go](../problems/reach-a-number) | Medium | | 755 | [Pour Water](https://leetcode.com/problems/pour-water "倒水") 🔒 | [Go](../problems/pour-water) | Medium | | 756 | [Pyramid Transition Matrix](https://leetcode.com/problems/pyramid-transition-matrix "金字塔转换矩阵") | [Go](../problems/pyramid-transition-matrix) | Medium | -| 757 | [Set Intersection Size At Least Two](https://leetcode.com/problems/set-intersection-size-at-least-two " 设置交集大小至少为2") | [Go](../problems/set-intersection-size-at-least-two) | Hard | +| 757 | [Set Intersection Size At Least Two](https://leetcode.com/problems/set-intersection-size-at-least-two "设置交集大小至少为2") | [Go](../problems/set-intersection-size-at-least-two) | Hard | | 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string "字符串中的加粗单词") 🔒 | [Go](../problems/bold-words-in-string) | Easy | | 759 | [Employee Free Time](https://leetcode.com/problems/employee-free-time "员工空闲时间") 🔒 | [Go](../problems/employee-free-time) | Hard | | 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings "找出变位映射") 🔒 | [Go](../problems/find-anagram-mappings) | Easy | diff --git a/readme/901-1200.md b/readme/901-1200.md index dfddde6e8..83f160153 100644 --- a/readme/901-1200.md +++ b/readme/901-1200.md @@ -196,7 +196,7 @@ LeetCode Problems' Solutions | 1024 | [Video Stitching](https://leetcode.com/problems/video-stitching "视频拼接") | [Go](../problems/video-stitching) | Medium | | 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game "除数博弈") | [Go](../problems/divisor-game) | Easy | | 1026 | [Maximum Difference Between Node and Ancestor](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor "节点与其祖先之间的最大差值") | [Go](../problems/maximum-difference-between-node-and-ancestor) | Medium | -| 1027 | [Longest Arithmetic Sequence](https://leetcode.com/problems/longest-arithmetic-sequence "最长等差数列") | [Go](../problems/longest-arithmetic-sequence) | Medium | +| 1027 | [Longest Arithmetic Subsequence](https://leetcode.com/problems/longest-arithmetic-subsequence "最长等差数列") | [Go](../problems/longest-arithmetic-subsequence) | Medium | | 1028 | [Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal "从先序遍历还原二叉树") | [Go](../problems/recover-a-tree-from-preorder-traversal) | Hard | | 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling "两地调度") | [Go](../problems/two-city-scheduling) | Easy | | 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order "距离顺序排列矩阵单元格") | [Go](../problems/matrix-cells-in-distance-order) | Easy | diff --git a/tag/array/README.md b/tag/array/README.md index 06f8ab50d..f5d1ecca2 100644 --- a/tag/array/README.md +++ b/tag/array/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1552 | [两球之间的磁力](../../problems/magnetic-force-between-two-balls) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | +| 1550 | [存在连续三个奇数的数组](../../problems/three-consecutive-odds) | [[数组](../array/README.md)] | Easy | | 1539 | [第 k 个缺失的正整数](../../problems/kth-missing-positive-number) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Easy | | 1535 | [找出数组游戏的赢家](../../problems/find-the-winner-of-an-array-game) | [[数组](../array/README.md)] | Medium | | 1534 | [统计好三元组](../../problems/count-good-triplets) | [[数组](../array/README.md)] | Easy | @@ -86,7 +88,7 @@ | 1233 | [删除子文件夹](../../problems/remove-sub-folders-from-the-filesystem) | [[数组](../array/README.md)] [[字符串](../string/README.md)] | Medium | | 1232 | [缀点成线](../../problems/check-if-it-is-a-straight-line) | [[几何](../geometry/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | | 1222 | [可以攻击国王的皇后](../../problems/queens-that-can-attack-the-king) | [[数组](../array/README.md)] | Medium | -| 1217 | [玩筹码](../../problems/play-with-chips) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | +| 1217 | [玩筹码](../../problems/minimum-cost-to-move-chips-to-the-same-position) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | | 1208 | [尽可能使字符串相等](../../problems/get-equal-substrings-within-budget) | [[数组](../array/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | | 1202 | [交换字符串中的元素](../../problems/smallest-string-with-swaps) | [[并查集](../union-find/README.md)] [[数组](../array/README.md)] | Medium | | 1200 | [最小绝对差](../../problems/minimum-absolute-difference) | [[数组](../array/README.md)] | Easy | diff --git a/tag/backtracking/README.md b/tag/backtracking/README.md index 277f11155..0eacba95d 100644 --- a/tag/backtracking/README.md +++ b/tag/backtracking/README.md @@ -42,7 +42,7 @@ | 254 | [因子的组合](../../problems/factor-combinations) 🔒 | [[回溯算法](../backtracking/README.md)] | Medium | | 216 | [组合总和 III](../../problems/combination-sum-iii) | [[数组](../array/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 212 | [单词搜索 II](../../problems/word-search-ii) | [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | -| 211 | [添加与搜索单词 - 数据结构设计](../../problems/add-and-search-word-data-structure-design) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | +| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 140 | [单词拆分 II](../../problems/word-break-ii) | [[动态规划](../dynamic-programming/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | | 131 | [分割回文串](../../problems/palindrome-partitioning) | [[回溯算法](../backtracking/README.md)] | Medium | | 126 | [单词接龙 II](../../problems/word-ladder-ii) | [[广度优先搜索](../breadth-first-search/README.md)] [[数组](../array/README.md)] [[字符串](../string/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | diff --git a/tag/binary-search/README.md b/tag/binary-search/README.md index 0c4e9ff38..6a61cce43 100644 --- a/tag/binary-search/README.md +++ b/tag/binary-search/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1552 | [两球之间的磁力](../../problems/magnetic-force-between-two-balls) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1533 | [Find the Index of the Large Integer](../../problems/find-the-index-of-the-large-integer) 🔒 | [[二分查找](../binary-search/README.md)] | Medium | | 1521 | [找到最接近目标值的函数值](../../problems/find-a-value-of-a-mysterious-function-closest-to-target) | [[位运算](../bit-manipulation/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] | Hard | | 1482 | [制作 m 束花所需的最少天数](../../problems/minimum-number-of-days-to-make-m-bouquets) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | diff --git a/tag/design/README.md b/tag/design/README.md index aabe94b12..ddf640c51 100644 --- a/tag/design/README.md +++ b/tag/design/README.md @@ -53,7 +53,7 @@ | 244 | [最短单词距离 II](../../problems/shortest-word-distance-ii) 🔒 | [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 232 | [用栈实现队列](../../problems/implement-queue-using-stacks) | [[栈](../stack/README.md)] [[设计](../design/README.md)] | Easy | | 225 | [用队列实现栈](../../problems/implement-stack-using-queues) | [[栈](../stack/README.md)] [[设计](../design/README.md)] | Easy | -| 211 | [添加与搜索单词 - 数据结构设计](../../problems/add-and-search-word-data-structure-design) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | +| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 208 | [实现 Trie (前缀树)](../../problems/implement-trie-prefix-tree) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] | Medium | | 173 | [二叉搜索树迭代器](../../problems/binary-search-tree-iterator) | [[栈](../stack/README.md)] [[树](../tree/README.md)] [[设计](../design/README.md)] | Medium | | 170 | [两数之和 III - 数据结构设计](../../problems/two-sum-iii-data-structure-design) 🔒 | [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Easy | diff --git a/tag/divide-and-conquer/README.md b/tag/divide-and-conquer/README.md index b0960f7f8..7ef87cf29 100644 --- a/tag/divide-and-conquer/README.md +++ b/tag/divide-and-conquer/README.md @@ -26,5 +26,5 @@ | 215 | [数组中的第K个最大元素](../../problems/kth-largest-element-in-an-array) | [[堆](../heap/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Medium | | 169 | [多数元素](../../problems/majority-element) | [[位运算](../bit-manipulation/README.md)] [[数组](../array/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Easy | | 53 | [最大子序和](../../problems/maximum-subarray) | [[数组](../array/README.md)] [[分治算法](../divide-and-conquer/README.md)] [[动态规划](../dynamic-programming/README.md)] | Easy | -| 23 | [合并K个排序链表](../../problems/merge-k-sorted-lists) | [[堆](../heap/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | +| 23 | [合并K个升序链表](../../problems/merge-k-sorted-lists) | [[堆](../heap/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | | 4 | [寻找两个正序数组的中位数](../../problems/median-of-two-sorted-arrays) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | diff --git a/tag/dynamic-programming/README.md b/tag/dynamic-programming/README.md index 7ebc2dcd8..f3ca6a0e7 100644 --- a/tag/dynamic-programming/README.md +++ b/tag/dynamic-programming/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1553 | [吃掉 N 个橘子的最少天数](../../problems/minimum-number-of-days-to-eat-n-oranges) | [[动态规划](../dynamic-programming/README.md)] | Hard | +| 1548 | [The Most Similar Path in a Graph](../../problems/the-most-similar-path-in-a-graph) 🔒 | [[图](../graph/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1547 | [切棍子的最小成本](../../problems/minimum-cost-to-cut-a-stick) | [[动态规划](../dynamic-programming/README.md)] | Hard | | 1546 | [和为目标值的最大数目不重叠非空子数组数目](../../problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 1537 | [最大得分](../../problems/get-the-maximum-score) | [[动态规划](../dynamic-programming/README.md)] | Hard | @@ -86,7 +88,7 @@ | 1049 | [最后一块石头的重量 II](../../problems/last-stone-weight-ii) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 1048 | [最长字符串链](../../problems/longest-string-chain) | [[哈希表](../hash-table/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1039 | [多边形三角剖分的最低得分](../../problems/minimum-score-triangulation-of-polygon) | [[动态规划](../dynamic-programming/README.md)] | Medium | -| 1027 | [最长等差数列](../../problems/longest-arithmetic-sequence) | [[动态规划](../dynamic-programming/README.md)] | Medium | +| 1027 | [最长等差数列](../../problems/longest-arithmetic-subsequence) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 1025 | [除数博弈](../../problems/divisor-game) | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Easy | | 1024 | [视频拼接](../../problems/video-stitching) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 1012 | [至少有 1 位重复的数字](../../problems/numbers-with-repeated-digits) | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | diff --git a/tag/graph/README.md b/tag/graph/README.md index 2175ba887..f2d1a1872 100644 --- a/tag/graph/README.md +++ b/tag/graph/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1548 | [The Most Similar Path in a Graph](../../problems/the-most-similar-path-in-a-graph) 🔒 | [[图](../graph/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1514 | [概率最大的路径](../../problems/path-with-maximum-probability) | [[图](../graph/README.md)] | Medium | | 1494 | [并行课程 II](../../problems/parallel-courses-ii) | [[图](../graph/README.md)] | Hard | | 1462 | [课程安排 IV](../../problems/course-schedule-iv) | [[图](../graph/README.md)] | Medium | diff --git a/tag/greedy/README.md b/tag/greedy/README.md index aeb3e12ef..5d2ea69a2 100644 --- a/tag/greedy/README.md +++ b/tag/greedy/README.md @@ -33,7 +33,7 @@ | 1247 | [交换字符使得字符串相同](../../problems/minimum-swaps-to-make-strings-equal) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] | Medium | | 1231 | [分享巧克力](../../problems/divide-chocolate) 🔒 | [[贪心算法](../greedy/README.md)] [[二分查找](../binary-search/README.md)] | Hard | | 1221 | [分割平衡字符串](../../problems/split-a-string-in-balanced-strings) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] | Easy | -| 1217 | [玩筹码](../../problems/play-with-chips) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | +| 1217 | [玩筹码](../../problems/minimum-cost-to-move-chips-to-the-same-position) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | | 1196 | [最多可以买到的苹果数量](../../problems/how-many-apples-can-you-put-into-the-basket) 🔒 | [[贪心算法](../greedy/README.md)] | Easy | | 1167 | [连接棒材的最低费用](../../problems/minimum-cost-to-connect-sticks) 🔒 | [[贪心算法](../greedy/README.md)] | Medium | | 1111 | [有效括号的嵌套深度](../../problems/maximum-nesting-depth-of-two-valid-parentheses-strings) | [[贪心算法](../greedy/README.md)] [[二分查找](../binary-search/README.md)] | Medium | @@ -67,7 +67,7 @@ | 765 | [情侣牵手](../../problems/couples-holding-hands) | [[贪心算法](../greedy/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Hard | | 763 | [划分字母区间](../../problems/partition-labels) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 759 | [员工空闲时间](../../problems/employee-free-time) 🔒 | [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] | Hard | -| 757 | [ 设置交集大小至少为2](../../problems/set-intersection-size-at-least-two) | [[贪心算法](../greedy/README.md)] | Hard | +| 757 | [设置交集大小至少为2](../../problems/set-intersection-size-at-least-two) | [[贪心算法](../greedy/README.md)] | Hard | | 738 | [单调递增的数字](../../problems/monotone-increasing-digits) | [[贪心算法](../greedy/README.md)] | Medium | | 714 | [买卖股票的最佳时机含手续费](../../problems/best-time-to-buy-and-sell-stock-with-transaction-fee) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 659 | [分割数组为连续子序列](../../problems/split-array-into-consecutive-subsequences) | [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] | Medium | diff --git a/tag/heap/README.md b/tag/heap/README.md index b815bcaee..47a8f4199 100644 --- a/tag/heap/README.md +++ b/tag/heap/README.md @@ -43,4 +43,4 @@ | 239 | [滑动窗口最大值](../../problems/sliding-window-maximum) | [[堆](../heap/README.md)] [[Sliding Window](../sliding-window/README.md)] | Hard | | 218 | [天际线问题](../../problems/the-skyline-problem) | [[堆](../heap/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[分治算法](../divide-and-conquer/README.md)] [[Line Sweep](../line-sweep/README.md)] | Hard | | 215 | [数组中的第K个最大元素](../../problems/kth-largest-element-in-an-array) | [[堆](../heap/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Medium | -| 23 | [合并K个排序链表](../../problems/merge-k-sorted-lists) | [[堆](../heap/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | +| 23 | [合并K个升序链表](../../problems/merge-k-sorted-lists) | [[堆](../heap/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | diff --git a/tag/linked-list/README.md b/tag/linked-list/README.md index f51d0b0c6..4d131fc44 100644 --- a/tag/linked-list/README.md +++ b/tag/linked-list/README.md @@ -44,7 +44,7 @@ | 61 | [旋转链表](../../problems/rotate-list) | [[链表](../linked-list/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 25 | [K 个一组翻转链表](../../problems/reverse-nodes-in-k-group) | [[链表](../linked-list/README.md)] | Hard | | 24 | [两两交换链表中的节点](../../problems/swap-nodes-in-pairs) | [[链表](../linked-list/README.md)] | Medium | -| 23 | [合并K个排序链表](../../problems/merge-k-sorted-lists) | [[堆](../heap/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | +| 23 | [合并K个升序链表](../../problems/merge-k-sorted-lists) | [[堆](../heap/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | | 21 | [合并两个有序链表](../../problems/merge-two-sorted-lists) | [[链表](../linked-list/README.md)] | Easy | | 19 | [删除链表的倒数第N个节点](../../problems/remove-nth-node-from-end-of-list) | [[链表](../linked-list/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 2 | [两数相加](../../problems/add-two-numbers) | [[链表](../linked-list/README.md)] [[数学](../math/README.md)] | Medium | diff --git a/tag/math/README.md b/tag/math/README.md index 6fdaf1fdc..4df5334bc 100644 --- a/tag/math/README.md +++ b/tag/math/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1551 | [使数组中所有元素相等的最小操作数](../../problems/minimum-operations-to-make-array-equal) | [[数学](../math/README.md)] | Medium | | 1524 | [和为奇数的子数组数目](../../problems/number-of-sub-arrays-with-odd-sum) | [[数组](../array/README.md)] [[数学](../math/README.md)] | Medium | | 1523 | [在区间范围内统计奇数数目](../../problems/count-odd-numbers-in-an-interval-range) | [[数学](../math/README.md)] | Easy | | 1513 | [仅含 1 的子串数](../../problems/number-of-substrings-with-only-1s) | [[数学](../math/README.md)] [[字符串](../string/README.md)] | Medium | @@ -44,7 +45,7 @@ | 1228 | [等差数列中缺失的数字](../../problems/missing-number-in-arithmetic-progression) 🔒 | [[数学](../math/README.md)] | Easy | | 1227 | [飞机座位分配概率](../../problems/airplane-seat-assignment-probability) | [[脑筋急转弯](../brainteaser/README.md)] [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1218 | [最长定差子序列](../../problems/longest-arithmetic-subsequence-of-given-difference) | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | -| 1217 | [玩筹码](../../problems/play-with-chips) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | +| 1217 | [玩筹码](../../problems/minimum-cost-to-move-chips-to-the-same-position) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | | 1201 | [丑数 III](../../problems/ugly-number-iii) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1199 | [建造街区的最短时间](../../problems/minimum-time-to-build-blocks) 🔒 | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1183 | [矩阵中 1 的最大数量](../../problems/maximum-number-of-ones) 🔒 | [[排序](../sort/README.md)] [[数学](../math/README.md)] | Hard | diff --git a/tag/tree/README.md b/tag/tree/README.md index 444961f7d..08171eddf 100644 --- a/tag/tree/README.md +++ b/tag/tree/README.md @@ -10,7 +10,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | | 1530 | [好叶子节点对的数量](../../problems/number-of-good-leaf-nodes-pairs) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | -| 1516 | [Move Sub-Tree of N-Ary Tree](../../problems/move-sub-tree-of-n-ary-tree) 🔒 | [[树](../tree/README.md)] | Hard | +| 1516 | [移动 N 叉树的子树](../../problems/move-sub-tree-of-n-ary-tree) 🔒 | [[树](../tree/README.md)] | Hard | | 1490 | [克隆 N 叉树](../../problems/clone-n-ary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1485 | [克隆含随机指针的二叉树](../../problems/clone-binary-tree-with-random-pointer) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 1469 | [寻找所有的独生节点](../../problems/find-all-the-lonely-nodes) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Easy | diff --git a/tag/trie/README.md b/tag/trie/README.md index 3bd66dc15..f0436f960 100644 --- a/tag/trie/README.md +++ b/tag/trie/README.md @@ -24,5 +24,5 @@ | 421 | [数组中两个数的最大异或值](../../problems/maximum-xor-of-two-numbers-in-an-array) | [[位运算](../bit-manipulation/README.md)] [[字典树](../trie/README.md)] | Medium | | 336 | [回文对](../../problems/palindrome-pairs) | [[字典树](../trie/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Hard | | 212 | [单词搜索 II](../../problems/word-search-ii) | [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | -| 211 | [添加与搜索单词 - 数据结构设计](../../problems/add-and-search-word-data-structure-design) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | +| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 208 | [实现 Trie (前缀树)](../../problems/implement-trie-prefix-tree) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] | Medium |