From 04c80dd37da6693cc79b239ab3506b3eeaa8afa7 Mon Sep 17 00:00:00 2001 From: Shuo Date: Mon, 13 Jan 2020 11:15:49 +0800 Subject: [PATCH] Add: new --- README.md | 22 +++-- problems/average-selling-price/README.md | 2 +- .../README.md | 81 +++++++++++++++++ .../README.md | 41 +++++++++ problems/distinct-echo-substrings/README.md | 58 +++++++++++++ problems/market-analysis-i/README.md | 2 +- problems/matrix-block-sum/README.md | 57 ++++++++++++ .../README.md | 86 +++++++++++++++++++ .../README.md | 57 ++++++++++++ .../README.md | 2 +- .../README.md | 80 +++++++++++++++++ problems/page-recommendations/README.md | 2 +- .../product-price-at-a-given-date/README.md | 2 +- problems/shift-2d-grid/README.md | 6 +- problems/similar-string-groups/README.md | 2 +- .../README.md | 50 +++++++++++ .../README.md | 2 +- .../README.md | 2 +- problems/user-purchase-platform/README.md | 2 +- tag/README.md | 4 +- tag/array/README.md | 1 + tag/bit-manipulation/README.md | 1 + tag/breadth-first-search/README.md | 1 + tag/depth-first-search/README.md | 2 + tag/dynamic-programming/README.md | 2 + tag/math/README.md | 1 + tag/string/README.md | 1 + tag/tags.json | 10 +-- tag/tree/README.md | 1 + tag/union-find/README.md | 1 + 30 files changed, 555 insertions(+), 26 deletions(-) create mode 100644 problems/convert-integer-to-the-sum-of-two-no-zero-integers/README.md create mode 100644 problems/decompress-run-length-encoded-list/README.md create mode 100644 problems/distinct-echo-substrings/README.md create mode 100644 problems/matrix-block-sum/README.md create mode 100644 problems/minimum-distance-to-type-a-word-using-two-fingers/README.md create mode 100644 problems/minimum-flips-to-make-a-or-b-equal-to-c/README.md create mode 100644 problems/number-of-operations-to-make-network-connected/README.md create mode 100644 problems/sum-of-nodes-with-even-valued-grandparent/README.md diff --git a/README.md b/README.md index b5c3e769d..ef96d64d4 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,14 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1320 | [Minimum Distance to Type a Word Using Two Fingers](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers "二指输入的的最小距离") | [Go](problems/minimum-distance-to-type-a-word-using-two-fingers) | Hard | +| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected "连通网络的操作次数") | [Go](problems/number-of-operations-to-make-network-connected) | Medium | +| 1318 | [Minimum Flips to Make a OR b Equal to c](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c "或运算的最小翻转次数") | [Go](problems/minimum-flips-to-make-a-or-b-equal-to-c) | Medium | +| 1317 | [Convert Integer to the Sum of Two No-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers "将整数转换为两个无零整数的和") | [Go](problems/convert-integer-to-the-sum-of-two-no-zero-integers) | Easy | +| 1316 | [Distinct Echo Substrings](https://leetcode.com/problems/distinct-echo-substrings "不同的循环子字符串") | [Go](problems/distinct-echo-substrings) | Hard | +| 1315 | [Sum of Nodes with Even-Valued Grandparent](https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent "祖父节点值为偶数的节点和") | [Go](problems/sum-of-nodes-with-even-valued-grandparent) | Medium | +| 1314 | [Matrix Block Sum](https://leetcode.com/problems/matrix-block-sum "矩阵区域和") | [Go](problems/matrix-block-sum) | Medium | +| 1313 | [Decompress Run-Length Encoded List](https://leetcode.com/problems/decompress-run-length-encoded-list "解压缩编码列表") | [Go](problems/decompress-run-length-encoded-list) | Easy | | 1312 | [Minimum Insertion Steps to Make a String Palindrome](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome "让字符串成为回文串的最少插入次数") | [Go](problems/minimum-insertion-steps-to-make-a-string-palindrome) | Hard | | 1311 | [Get Watched Videos by Your Friends](https://leetcode.com/problems/get-watched-videos-by-your-friends "获取你好友已观看的视频") | [Go](problems/get-watched-videos-by-your-friends) | Medium | | 1310 | [XOR Queries of a Subarray](https://leetcode.com/problems/xor-queries-of-a-subarray "子数组异或查询") | [Go](problems/xor-queries-of-a-subarray) | Medium | @@ -95,7 +103,7 @@ LeetCode Problems' Solutions | 1282 | [Group the People Given the Group Size They Belong To](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to "用户分组") | [Go](problems/group-the-people-given-the-group-size-they-belong-to) | Medium | | 1281 | [Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer "整数的各位积和之差") | [Go](problems/subtract-the-product-and-sum-of-digits-of-an-integer) | Easy | | 1280 | [Students and Examinations](https://leetcode.com/problems/students-and-examinations "学生们参加各科测试的次数") 🔒 | [MySQL](problems/students-and-examinations) | Easy | -| 1279 | [Traffic Light Controlled Intersection](https://leetcode.com/problems/traffic-light-controlled-intersection) 🔒 | [Go](problems/traffic-light-controlled-intersection) | Easy | +| 1279 | [Traffic Light Controlled Intersection](https://leetcode.com/problems/traffic-light-controlled-intersection "红绿灯路口") 🔒 | [Go](problems/traffic-light-controlled-intersection) | Easy | | 1278 | [Palindrome Partitioning III](https://leetcode.com/problems/palindrome-partitioning-iii "分割回文串 III") | [Go](problems/palindrome-partitioning-iii) | Hard | | 1277 | [Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones "统计全为 1 的正方形子矩阵") | [Go](problems/count-square-submatrices-with-all-ones) | Medium | | 1276 | [Number of Burgers with No Waste of Ingredients](https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients "不浪费原料的汉堡制作方案") | [Go](problems/number-of-burgers-with-no-waste-of-ingredients) | Medium | @@ -110,7 +118,7 @@ LeetCode Problems' Solutions | 1267 | [Count Servers that Communicate](https://leetcode.com/problems/count-servers-that-communicate "统计参与通信的服务器") | [Go](problems/count-servers-that-communicate) | Medium | | 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points "访问所有点的最小时间") | [Go](problems/minimum-time-visiting-all-points) | Easy | | 1265 | [Print Immutable Linked List in Reverse](https://leetcode.com/problems/print-immutable-linked-list-in-reverse "逆序打印不可变链表") 🔒 | [Go](problems/print-immutable-linked-list-in-reverse) | Medium | -| 1264 | [Page Recommendations](https://leetcode.com/problems/page-recommendations) 🔒 | [MySQL](problems/page-recommendations) | Medium | +| 1264 | [Page Recommendations](https://leetcode.com/problems/page-recommendations "页面推荐") 🔒 | [MySQL](problems/page-recommendations) | Medium | | 1263 | [Minimum Moves to Move a Box to Their Target Location](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location "推箱子") | [Go](problems/minimum-moves-to-move-a-box-to-their-target-location) | Hard | | 1262 | [Greatest Sum Divisible by Three](https://leetcode.com/problems/greatest-sum-divisible-by-three "可被三整除的最大和") | [Go](problems/greatest-sum-divisible-by-three) | Medium | | 1261 | [Find Elements in a Contaminated Binary Tree](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree "在受污染的二叉树中查找元素") | [Go](problems/find-elements-in-a-contaminated-binary-tree) | Medium | @@ -123,7 +131,7 @@ LeetCode Problems' Solutions | 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands "统计封闭岛屿的数目") | [Go](problems/number-of-closed-islands) | Medium | | 1253 | [Reconstruct a 2-Row Binary Matrix](https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix "重构 2 行二进制矩阵") | [Go](problems/reconstruct-a-2-row-binary-matrix) | Medium | | 1252 | [Cells with Odd Values in a Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix "奇数值单元格的数目") | [Go](problems/cells-with-odd-values-in-a-matrix) | Easy | -| 1251 | [Average Selling Price](https://leetcode.com/problems/average-selling-price) 🔒 | [MySQL](problems/average-selling-price) | Easy | +| 1251 | [Average Selling Price](https://leetcode.com/problems/average-selling-price "平均售价") 🔒 | [MySQL](problems/average-selling-price) | Easy | | 1250 | [Check If It Is a Good Array](https://leetcode.com/problems/check-if-it-is-a-good-array "检查「好数组」") | [Go](problems/check-if-it-is-a-good-array) | Hard | | 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses "移除无效的括号") | [Go](problems/minimum-remove-to-make-valid-parentheses) | Medium | | 1248 | [Count Number of Nice Subarrays](https://leetcode.com/problems/count-number-of-nice-subarrays "统计「优美子数组」") | [Go](problems/count-number-of-nice-subarrays) | Medium | @@ -162,7 +170,7 @@ LeetCode Problems' Solutions | 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 | | 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays "三个有序数组的交集") 🔒 | [Go](problems/intersection-of-three-sorted-arrays) | Easy | -| 1212 | [Team Scores in Football Tournament](https://leetcode.com/problems/team-scores-in-football-tournament) 🔒 | [MySQL](problems/team-scores-in-football-tournament) | Medium | +| 1212 | [Team Scores in Football Tournament](https://leetcode.com/problems/team-scores-in-football-tournament "查询球队积分") 🔒 | [MySQL](problems/team-scores-in-football-tournament) | Medium | | 1211 | [Queries Quality and Percentage](https://leetcode.com/problems/queries-quality-and-percentage) 🔒 | [MySQL](problems/queries-quality-and-percentage) | Easy | | 1210 | [Minimum Moves to Reach Target with Rotations](https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations "穿过迷宫的最少移动次数") | [Go](problems/minimum-moves-to-reach-target-with-rotations) | Hard | | 1209 | [Remove All Adjacent Duplicates in String II](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii "删除字符串中的所有相邻重复项 II") | [Go](problems/remove-all-adjacent-duplicates-in-string-ii) | Medium | @@ -210,13 +218,13 @@ LeetCode Problems' Solutions | 1167 | [Minimum Cost to Connect Sticks](https://leetcode.com/problems/minimum-cost-to-connect-sticks "连接棒材的最低费用") 🔒 | [Go](problems/minimum-cost-to-connect-sticks) | Medium | | 1166 | [Design File System](https://leetcode.com/problems/design-file-system "设计文件系统") 🔒 | [Go](problems/design-file-system) | Medium | | 1165 | [Single-Row Keyboard](https://leetcode.com/problems/single-row-keyboard "单行键盘") 🔒 | [Go](problems/single-row-keyboard) | Easy | -| 1164 | [Product Price at a Given Date](https://leetcode.com/problems/product-price-at-a-given-date) 🔒 | [MySQL](problems/product-price-at-a-given-date) | Medium | +| 1164 | [Product Price at a Given Date](https://leetcode.com/problems/product-price-at-a-given-date "指定日期的产品价格") 🔒 | [MySQL](problems/product-price-at-a-given-date) | Medium | | 1163 | [Last Substring in Lexicographical Order](https://leetcode.com/problems/last-substring-in-lexicographical-order "按字典序排在最后的子串") | [Go](problems/last-substring-in-lexicographical-order) | Hard | | 1162 | [As Far from Land as Possible](https://leetcode.com/problems/as-far-from-land-as-possible "地图分析") | [Go](problems/as-far-from-land-as-possible) | Medium | | 1161 | [Maximum Level Sum of a Binary Tree](https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree "最大层内元素和") | [Go](problems/maximum-level-sum-of-a-binary-tree) | Medium | | 1160 | [Find Words That Can Be Formed by Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters "拼写单词") | [Go](problems/find-words-that-can-be-formed-by-characters) | Easy | | 1159 | [Market Analysis II](https://leetcode.com/problems/market-analysis-ii) 🔒 | [MySQL](problems/market-analysis-ii) | Hard | -| 1158 | [Market Analysis I](https://leetcode.com/problems/market-analysis-i) 🔒 | [MySQL](problems/market-analysis-i) | Medium | +| 1158 | [Market Analysis I](https://leetcode.com/problems/market-analysis-i "市场分析 I") 🔒 | [MySQL](problems/market-analysis-i) | Medium | | 1157 | [Online Majority Element In Subarray](https://leetcode.com/problems/online-majority-element-in-subarray "子数组中占绝大多数的元素") | [Go](problems/online-majority-element-in-subarray) | Hard | | 1156 | [Swap For Longest Repeated Character Substring](https://leetcode.com/problems/swap-for-longest-repeated-character-substring "单字符重复子串的最大长度") | [Go](problems/swap-for-longest-repeated-character-substring) | Medium | | 1155 | [Number of Dice Rolls With Target Sum](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum "掷骰子的N种方法") | [Go](problems/number-of-dice-rolls-with-target-sum) | Medium | @@ -247,7 +255,7 @@ LeetCode Problems' Solutions | 1130 | [Minimum Cost Tree From Leaf Values](https://leetcode.com/problems/minimum-cost-tree-from-leaf-values "叶值的最小代价生成树") | [Go](problems/minimum-cost-tree-from-leaf-values) | Medium | | 1129 | [Shortest Path with Alternating Colors](https://leetcode.com/problems/shortest-path-with-alternating-colors "颜色交替的最短路径") | [Go](problems/shortest-path-with-alternating-colors) | Medium | | 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs "等价多米诺骨牌对的数量") | [Go](problems/number-of-equivalent-domino-pairs) | Easy | -| 1127 | [User Purchase Platform](https://leetcode.com/problems/user-purchase-platform) 🔒 | [MySQL](problems/user-purchase-platform) | Hard | +| 1127 | [User Purchase Platform](https://leetcode.com/problems/user-purchase-platform "用户购买平台") 🔒 | [MySQL](problems/user-purchase-platform) | Hard | | 1126 | [Active Businesses](https://leetcode.com/problems/active-businesses "查询活跃业务") 🔒 | [MySQL](problems/active-businesses) | Medium | | 1125 | [Smallest Sufficient Team](https://leetcode.com/problems/smallest-sufficient-team "最小的必要团队") | [Go](problems/smallest-sufficient-team) | Hard | | 1124 | [Longest Well-Performing Interval](https://leetcode.com/problems/longest-well-performing-interval "表现良好的最长时间段") | [Go](problems/longest-well-performing-interval) | Medium | diff --git a/problems/average-selling-price/README.md b/problems/average-selling-price/README.md index db5550bb4..8eee2ff1e 100644 --- a/problems/average-selling-price/README.md +++ b/problems/average-selling-price/README.md @@ -9,7 +9,7 @@                  [Next >](../cells-with-odd-values-in-a-matrix "Cells with Odd Values in a Matrix") -## [1251. Average Selling Price (Easy)](https://leetcode.com/problems/average-selling-price "") +## [1251. Average Selling Price (Easy)](https://leetcode.com/problems/average-selling-price "平均售价")

Table: Prices

diff --git a/problems/convert-integer-to-the-sum-of-two-no-zero-integers/README.md b/problems/convert-integer-to-the-sum-of-two-no-zero-integers/README.md new file mode 100644 index 000000000..1d4bf848c --- /dev/null +++ b/problems/convert-integer-to-the-sum-of-two-no-zero-integers/README.md @@ -0,0 +1,81 @@ + + + + + + + +[< Previous](../distinct-echo-substrings "Distinct Echo Substrings") +                 +[Next >](../minimum-flips-to-make-a-or-b-equal-to-c "Minimum Flips to Make a OR b Equal to c") + +## [1317. Convert Integer to the Sum of Two No-Zero Integers (Easy)](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers "将整数转换为两个无零整数的和") + +

Given an integer n. No-Zero integer is a positive integer which doesn't contain any 0 in its decimal representation.

+ +

Return a list of two integers [A, B] where:

+ + + +

It's guarateed that there is at least one valid solution. If there are many valid solutions you can return any of them.

+ +

 

+

Example 1:

+ +
+Input: n = 2
+Output: [1,1]
+Explanation: A = 1, B = 1. A + B = n and both A and B don't contain any 0 in their decimal representation.
+
+ +

Example 2:

+ +
+Input: n = 11
+Output: [2,9]
+
+ +

Example 3:

+ +
+Input: n = 10000
+Output: [1,9999]
+
+ +

Example 4:

+ +
+Input: n = 69
+Output: [1,68]
+
+ +

Example 5:

+ +
+Input: n = 1010
+Output: [11,999]
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Math](../../tag/math/README.md)] + +### Hints +
+Hint 1 +Loop through all elements from 1 to n. +
+ +
+Hint 2 +Choose A = i and B = n - i then check if A and B are both No-Zero integers. +
diff --git a/problems/decompress-run-length-encoded-list/README.md b/problems/decompress-run-length-encoded-list/README.md new file mode 100644 index 000000000..e6d524263 --- /dev/null +++ b/problems/decompress-run-length-encoded-list/README.md @@ -0,0 +1,41 @@ + + + + + + + +[< Previous](../minimum-insertion-steps-to-make-a-string-palindrome "Minimum Insertion Steps to Make a String Palindrome") +                 +[Next >](../matrix-block-sum "Matrix Block Sum") + +## [1313. Decompress Run-Length Encoded List (Easy)](https://leetcode.com/problems/decompress-run-length-encoded-list "解压缩编码列表") + +

We are given a list nums of integers representing a list compressed with run-length encoding.

+ +

Consider each adjacent pair of elements [a, b] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there are a elements with value b in the decompressed list.

+ +

Return the decompressed list.

+ +

 

+

Example 1:

+
Input: nums = [1,2,3,4]
+Output: [2,4,4,4]
+
+

 

+

Constraints:

+ + + +### Related Topics + [[Array](../../tag/array/README.md)] + +### Hints +
+Hint 1 +Decompress the given array by repeating nums[2*i+1] a number of times equal to nums[2*i]. +
diff --git a/problems/distinct-echo-substrings/README.md b/problems/distinct-echo-substrings/README.md new file mode 100644 index 000000000..58a16978f --- /dev/null +++ b/problems/distinct-echo-substrings/README.md @@ -0,0 +1,58 @@ + + + + + + + +[< Previous](../sum-of-nodes-with-even-valued-grandparent "Sum of Nodes with Even-Valued Grandparent") +                 +[Next >](../convert-integer-to-the-sum-of-two-no-zero-integers "Convert Integer to the Sum of Two No-Zero Integers") + +## [1316. Distinct Echo Substrings (Hard)](https://leetcode.com/problems/distinct-echo-substrings "不同的循环子字符串") + +

Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself.

+ +

 

+

Example 1:

+ +
+Input: text = "abcabcabc"
+Output: 3
+Explanation: The 3 substrings are "abcabc", "bcabca" and "cabcab".
+
+ +

Example 2:

+ +
+Input: text = "leetcodeleetcode"
+Output: 2
+Explanation: The 2 substrings are "ee" and "leetcodeleetcode".
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[String](../../tag/string/README.md)] + +### Hints +
+Hint 1 +Given a substring of the text, how to check if it can be written as the concatenation of a string with itself ? +
+ +
+Hint 2 +We can do that in linear time, a faster way is to use hashing. +
+ +
+Hint 3 +Try all substrings and use hashing to check them. +
diff --git a/problems/market-analysis-i/README.md b/problems/market-analysis-i/README.md index 076ba31a2..16d679b4c 100644 --- a/problems/market-analysis-i/README.md +++ b/problems/market-analysis-i/README.md @@ -9,7 +9,7 @@                  [Next >](../market-analysis-ii "Market Analysis II") -## [1158. Market Analysis I (Medium)](https://leetcode.com/problems/market-analysis-i "") +## [1158. Market Analysis I (Medium)](https://leetcode.com/problems/market-analysis-i "市场分析 I")

Table: Users

diff --git a/problems/matrix-block-sum/README.md b/problems/matrix-block-sum/README.md new file mode 100644 index 000000000..177fee58e --- /dev/null +++ b/problems/matrix-block-sum/README.md @@ -0,0 +1,57 @@ + + + + + + + +[< Previous](../decompress-run-length-encoded-list "Decompress Run-Length Encoded List") +                 +[Next >](../sum-of-nodes-with-even-valued-grandparent "Sum of Nodes with Even-Valued Grandparent") + +## [1314. Matrix Block Sum (Medium)](https://leetcode.com/problems/matrix-block-sum "矩阵区域和") + +Given a m * n matrix mat and an integer K, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for i - K <= r <= i + K, j - K <= c <= j + K, and (r, c) is a valid position in the matrix. +

 

+

Example 1:

+ +
+Input: mat = [[1,2,3],[4,5,6],[7,8,9]], K = 1
+Output: [[12,21,16],[27,45,33],[24,39,28]]
+
+ +

Example 2:

+ +
+Input: mat = [[1,2,3],[4,5,6],[7,8,9]], K = 2
+Output: [[45,45,45],[45,45,45],[45,45,45]]
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +How to calculate the required sum for a cell (i,j) fast ? +
+ +
+Hint 2 +Use the concept of cumulative sum array. +
+ +
+Hint 3 +Create a cumulative sum matrix where dp[i][j] is the sum of all cells in the rectangle from (0,0) to (i,j), use inclusion-exclusion idea. +
diff --git a/problems/minimum-distance-to-type-a-word-using-two-fingers/README.md b/problems/minimum-distance-to-type-a-word-using-two-fingers/README.md new file mode 100644 index 000000000..bd82d9adc --- /dev/null +++ b/problems/minimum-distance-to-type-a-word-using-two-fingers/README.md @@ -0,0 +1,86 @@ + + + + + + + +[< Previous](../number-of-operations-to-make-network-connected "Number of Operations to Make Network Connected") +                 +Next > + +## [1320. Minimum Distance to Type a Word Using Two Fingers (Hard)](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers "二指输入的的最小距离") + +

+ +

You have a keyboard layout as shown above in the XY plane, where each English uppercase letter is located at some coordinate, for example, the letter A is located at coordinate (0,0), the letter B is located at coordinate (0,1), the letter P is located at coordinate (2,3) and the letter Z is located at coordinate (4,1).

+ +

Given the string word, return the minimum total distance to type such string using only two fingers. The distance between coordinates (x1,y1) and (x2,y2) is |x1 - x2| + |y1 - y2|

+ +

Note that the initial positions of your two fingers are considered free so don't count towards your total distance, also your two fingers do not have to start at the first letter or the first two letters.

+ +

 

+

Example 1:

+ +
+Input: word = "CAKE"
+Output: 3
+Explanation: 
+Using two fingers, one optimal way to type "CAKE" is: 
+Finger 1 on letter 'C' -> cost = 0 
+Finger 1 on letter 'A' -> cost = Distance from letter 'C' to letter 'A' = 2 
+Finger 2 on letter 'K' -> cost = 0 
+Finger 2 on letter 'E' -> cost = Distance from letter 'K' to letter 'E' = 1 
+Total distance = 3
+
+ +

Example 2:

+ +
+Input: word = "HAPPY"
+Output: 6
+Explanation: 
+Using two fingers, one optimal way to type "HAPPY" is:
+Finger 1 on letter 'H' -> cost = 0
+Finger 1 on letter 'A' -> cost = Distance from letter 'H' to letter 'A' = 2
+Finger 2 on letter 'P' -> cost = 0
+Finger 2 on letter 'P' -> cost = Distance from letter 'P' to letter 'P' = 0
+Finger 1 on letter 'Y' -> cost = Distance from letter 'A' to letter 'Y' = 4
+Total distance = 6
+
+ +

Example 3:

+ +
+Input: word = "NEW"
+Output: 3
+
+ +

Example 4:

+ +
+Input: word = "YEAR"
+Output: 7
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +Use dynamic programming. +
+ +
+Hint 2 +dp[i][j][k]: smallest movements when you have one finger on i-th char and the other one on j-th char already having written k first characters from word. +
diff --git a/problems/minimum-flips-to-make-a-or-b-equal-to-c/README.md b/problems/minimum-flips-to-make-a-or-b-equal-to-c/README.md new file mode 100644 index 000000000..e9644a5ae --- /dev/null +++ b/problems/minimum-flips-to-make-a-or-b-equal-to-c/README.md @@ -0,0 +1,57 @@ + + + + + + + +[< Previous](../convert-integer-to-the-sum-of-two-no-zero-integers "Convert Integer to the Sum of Two No-Zero Integers") +                 +[Next >](../number-of-operations-to-make-network-connected "Number of Operations to Make Network Connected") + +## [1318. Minimum Flips to Make a OR b Equal to c (Medium)](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c "或运算的最小翻转次数") + +

Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation).
+Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.

+ +

 

+

Example 1:

+ +

+ +
+Input: a = 2, b = 6, c = 5
+Output: 3
+Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c)
+ +

Example 2:

+ +
+Input: a = 4, b = 2, c = 7
+Output: 1
+
+ +

Example 3:

+ +
+Input: a = 1, b = 2, c = 3
+Output: 0
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Bit Manipulation](../../tag/bit-manipulation/README.md)] + +### Hints +
+Hint 1 +Check the bits one by one whether they need to be flipped. +
diff --git a/problems/minimum-insertion-steps-to-make-a-string-palindrome/README.md b/problems/minimum-insertion-steps-to-make-a-string-palindrome/README.md index 6d4b720ef..2dfd15089 100644 --- a/problems/minimum-insertion-steps-to-make-a-string-palindrome/README.md +++ b/problems/minimum-insertion-steps-to-make-a-string-palindrome/README.md @@ -7,7 +7,7 @@ [< Previous](../get-watched-videos-by-your-friends "Get Watched Videos by Your Friends")                  -Next > +[Next >](../decompress-run-length-encoded-list "Decompress Run-Length Encoded List") ## [1312. Minimum Insertion Steps to Make a String Palindrome (Hard)](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome "让字符串成为回文串的最少插入次数") diff --git a/problems/number-of-operations-to-make-network-connected/README.md b/problems/number-of-operations-to-make-network-connected/README.md new file mode 100644 index 000000000..b7c2144ba --- /dev/null +++ b/problems/number-of-operations-to-make-network-connected/README.md @@ -0,0 +1,80 @@ + + + + + + + +[< Previous](../minimum-flips-to-make-a-or-b-equal-to-c "Minimum Flips to Make a OR b Equal to c") +                 +[Next >](../minimum-distance-to-type-a-word-using-two-fingers "Minimum Distance to Type a Word Using Two Fingers") + +## [1319. Number of Operations to Make Network Connected (Medium)](https://leetcode.com/problems/number-of-operations-to-make-network-connected "连通网络的操作次数") + +

There are n computers numbered from 0 to n-1 connected by ethernet cables connections forming a network where connections[i] = [a, b] represents a connection between computers a and b. Any computer can reach any other computer directly or indirectly through the network.

+ +

Given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connected. Return the minimum number of times you need to do this in order to make all the computers connected. If it's not possible, return -1. 

+ +

 

+

Example 1:

+ +

+ +
+Input: n = 4, connections = [[0,1],[0,2],[1,2]]
+Output: 1
+Explanation: Remove cable between computer 1 and 2 and place between computers 1 and 3.
+
+ +

Example 2:

+ +

+ +
+Input: n = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]
+Output: 2
+
+ +

Example 3:

+ +
+Input: n = 6, connections = [[0,1],[0,2],[0,3],[1,2]]
+Output: -1
+Explanation: There are not enough cables.
+
+ +

Example 4:

+ +
+Input: n = 5, connections = [[0,1],[0,2],[3,4],[2,3]]
+Output: 0
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Depth-first Search](../../tag/depth-first-search/README.md)] + [[Breadth-first Search](../../tag/breadth-first-search/README.md)] + [[Union Find](../../tag/union-find/README.md)] + +### Hints +
+Hint 1 +As long as there are at least (n - 1) connections, there is definitely a way to connect all computers. +
+ +
+Hint 2 +Use DFS to determine the number of isolated computer clusters. +
diff --git a/problems/page-recommendations/README.md b/problems/page-recommendations/README.md index e7a369734..e90b60e6c 100644 --- a/problems/page-recommendations/README.md +++ b/problems/page-recommendations/README.md @@ -9,7 +9,7 @@                  [Next >](../print-immutable-linked-list-in-reverse "Print Immutable Linked List in Reverse") -## [1264. Page Recommendations (Medium)](https://leetcode.com/problems/page-recommendations "") +## [1264. Page Recommendations (Medium)](https://leetcode.com/problems/page-recommendations "页面推荐")

Table: Friendship

diff --git a/problems/product-price-at-a-given-date/README.md b/problems/product-price-at-a-given-date/README.md
index e03c4c84c..f1a5121e4 100644
--- a/problems/product-price-at-a-given-date/README.md
+++ b/problems/product-price-at-a-given-date/README.md
@@ -9,7 +9,7 @@
                 
 [Next >](../single-row-keyboard "Single-Row Keyboard")
 
-## [1164. Product Price at a Given Date (Medium)](https://leetcode.com/problems/product-price-at-a-given-date "")
+## [1164. Product Price at a Given Date (Medium)](https://leetcode.com/problems/product-price-at-a-given-date "指定日期的产品价格")
 
 

Table: Products

diff --git a/problems/shift-2d-grid/README.md b/problems/shift-2d-grid/README.md index e211a7e43..5d3f2674d 100644 --- a/problems/shift-2d-grid/README.md +++ b/problems/shift-2d-grid/README.md @@ -16,9 +16,9 @@

In one shift operation:

Return the 2D grid after applying shift operation k times.

diff --git a/problems/similar-string-groups/README.md b/problems/similar-string-groups/README.md index 2823d4505..1f01cae1a 100644 --- a/problems/similar-string-groups/README.md +++ b/problems/similar-string-groups/README.md @@ -11,7 +11,7 @@ ## [839. Similar String Groups (Hard)](https://leetcode.com/problems/similar-string-groups "相似字符串组") -

Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y.

+

Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y. Also two strings X and Y are similar if they are equal.

For example, "tars" and "rats" are similar (swapping at positions 0 and 2), and "rats" and "arts" are similar, but "star" is not similar to "tars", "rats", or "arts".

diff --git a/problems/sum-of-nodes-with-even-valued-grandparent/README.md b/problems/sum-of-nodes-with-even-valued-grandparent/README.md new file mode 100644 index 000000000..758aa7a6b --- /dev/null +++ b/problems/sum-of-nodes-with-even-valued-grandparent/README.md @@ -0,0 +1,50 @@ + + + + + + + +[< Previous](../matrix-block-sum "Matrix Block Sum") +                 +[Next >](../distinct-echo-substrings "Distinct Echo Substrings") + +## [1315. Sum of Nodes with Even-Valued Grandparent (Medium)](https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent "祖父节点值为偶数的节点和") + +

Given a binary tree, return the sum of values of nodes with even-valued grandparent.  (A grandparent of a node is the parent of its parent, if it exists.)

+ +

If there are no nodes with an even-valued grandparent, return 0.

+ +

 

+

Example 1:

+ +

+ +
+Input: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]
+Output: 18
+Explanation: The red nodes are the nodes with even-value grandparent while the blue nodes are the even-value grandparents.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Tree](../../tag/tree/README.md)] + [[Depth-first Search](../../tag/depth-first-search/README.md)] + +### Hints +
+Hint 1 +Traverse the tree keeping the parent and the grandparent. +
+ +
+Hint 2 +If the grandparent of the current node is even-valued, add the value of this node to the answer. +
diff --git a/problems/team-scores-in-football-tournament/README.md b/problems/team-scores-in-football-tournament/README.md index b2540c4ef..003c3bc81 100644 --- a/problems/team-scores-in-football-tournament/README.md +++ b/problems/team-scores-in-football-tournament/README.md @@ -9,7 +9,7 @@                  [Next >](../intersection-of-three-sorted-arrays "Intersection of Three Sorted Arrays") -## [1212. Team Scores in Football Tournament (Medium)](https://leetcode.com/problems/team-scores-in-football-tournament "") +## [1212. Team Scores in Football Tournament (Medium)](https://leetcode.com/problems/team-scores-in-football-tournament "查询球队积分")

Table: Teams

diff --git a/problems/traffic-light-controlled-intersection/README.md b/problems/traffic-light-controlled-intersection/README.md index 66e92e498..e27e50ea7 100644 --- a/problems/traffic-light-controlled-intersection/README.md +++ b/problems/traffic-light-controlled-intersection/README.md @@ -9,7 +9,7 @@                  [Next >](../students-and-examinations "Students and Examinations") -## [1279. Traffic Light Controlled Intersection (Easy)](https://leetcode.com/problems/traffic-light-controlled-intersection "") +## [1279. Traffic Light Controlled Intersection (Easy)](https://leetcode.com/problems/traffic-light-controlled-intersection "红绿灯路口") There is an intersection of two roads. First road is road A where cars travel from North to South in direction 1 and from South to North in direction 2. Second road is road B where cars travel from West to East in direction 3 and from East to West in direction 4. diff --git a/problems/user-purchase-platform/README.md b/problems/user-purchase-platform/README.md index 181aefec5..74e191305 100644 --- a/problems/user-purchase-platform/README.md +++ b/problems/user-purchase-platform/README.md @@ -9,7 +9,7 @@                  [Next >](../number-of-equivalent-domino-pairs "Number of Equivalent Domino Pairs") -## [1127. User Purchase Platform (Hard)](https://leetcode.com/problems/user-purchase-platform "") +## [1127. User Purchase Platform (Hard)](https://leetcode.com/problems/user-purchase-platform "用户购买平台")

Table: Spending

diff --git a/tag/README.md b/tag/README.md index f30727ce6..02b484368 100644 --- a/tag/README.md +++ b/tag/README.md @@ -27,5 +27,5 @@ | 31 | [Random](random/README.md) | [Random](https://openset.github.io/tags/random/) | | 32 | [Topological Sort](topological-sort/README.md) | [拓扑排序](https://openset.github.io/tags/topological-sort/) | | 33 | [Brainteaser](brainteaser/README.md) | [脑筋急转弯](https://openset.github.io/tags/brainteaser/) | | 34 | [Geometry](geometry/README.md) | [几何](https://openset.github.io/tags/geometry/) | | 35 | [Binary Search Tree](binary-search-tree/README.md) | [二叉搜索树](https://openset.github.io/tags/binary-search-tree/) | | 36 | [Rejection Sampling](rejection-sampling/README.md) | [Rejection Sampling](https://openset.github.io/tags/rejection-sampling/) | -| 37 | [Reservoir Sampling](reservoir-sampling/README.md) | [蓄水池抽样](https://openset.github.io/tags/reservoir-sampling/) | | 38 | [Memoization](memoization/README.md) | [记忆化](https://openset.github.io/tags/memoization/) | -| 39 | [Rolling Hash](rolling-hash/README.md) | [Rolling Hash](https://openset.github.io/tags/rolling-hash/) | | 40 | [Suffix Array](suffix-array/README.md) | [Suffix Array](https://openset.github.io/tags/suffix-array/) | +| 37 | [Reservoir Sampling](reservoir-sampling/README.md) | [蓄水池抽样](https://openset.github.io/tags/reservoir-sampling/) | | 38 | [Rolling Hash](rolling-hash/README.md) | [Rolling Hash](https://openset.github.io/tags/rolling-hash/) | +| 39 | [Memoization](memoization/README.md) | [记忆化](https://openset.github.io/tags/memoization/) | | 40 | [Suffix Array](suffix-array/README.md) | [Suffix Array](https://openset.github.io/tags/suffix-array/) | diff --git a/tag/array/README.md b/tag/array/README.md index 8ad504fec..5e864adc6 100644 --- a/tag/array/README.md +++ b/tag/array/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1313 | [解压缩编码列表](../../problems/decompress-run-length-encoded-list) | [[数组](../array/README.md)] | Easy | | 1304 | [和为零的N个唯一整数](../../problems/find-n-unique-integers-sum-up-to-zero) | [[数组](../array/README.md)] | Easy | | 1300 | [转变数组后最接近目标值的数组和](../../problems/sum-of-mutated-array-closest-to-target) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1299 | [将每个元素替换为右侧最大元素](../../problems/replace-elements-with-greatest-element-on-right-side) | [[数组](../array/README.md)] | Easy | diff --git a/tag/bit-manipulation/README.md b/tag/bit-manipulation/README.md index 637201e0d..560688625 100644 --- a/tag/bit-manipulation/README.md +++ b/tag/bit-manipulation/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1318 | [或运算的最小翻转次数](../../problems/minimum-flips-to-make-a-or-b-equal-to-c) | [[位运算](../bit-manipulation/README.md)] | Medium | | 1310 | [子数组异或查询](../../problems/xor-queries-of-a-subarray) | [[位运算](../bit-manipulation/README.md)] | Medium | | 1297 | [子串的最大出现次数](../../problems/maximum-number-of-occurrences-of-a-substring) | [[位运算](../bit-manipulation/README.md)] [[字符串](../string/README.md)] | Medium | | 1290 | [二进制链表转整数](../../problems/convert-binary-number-in-a-linked-list-to-integer) | [[位运算](../bit-manipulation/README.md)] [[链表](../linked-list/README.md)] | Easy | diff --git a/tag/breadth-first-search/README.md b/tag/breadth-first-search/README.md index aaef8bbae..cfd690bd3 100644 --- a/tag/breadth-first-search/README.md +++ b/tag/breadth-first-search/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1319 | [连通网络的操作次数](../../problems/number-of-operations-to-make-network-connected) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | | 1311 | [获取你好友已观看的视频](../../problems/get-watched-videos-by-your-friends) | [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Medium | | 1306 | [跳跃游戏 III](../../problems/jump-game-iii) | [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | | 1298 | [你能从盒子里获得的最大糖果数](../../problems/maximum-candies-you-can-get-from-boxes) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | diff --git a/tag/depth-first-search/README.md b/tag/depth-first-search/README.md index a9a13bd81..ccbe74420 100644 --- a/tag/depth-first-search/README.md +++ b/tag/depth-first-search/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1319 | [连通网络的操作次数](../../problems/number-of-operations-to-make-network-connected) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | +| 1315 | [祖父节点值为偶数的节点和](../../problems/sum-of-nodes-with-even-valued-grandparent) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 1302 | [层数最深叶子节点的和](../../problems/deepest-leaves-sum) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 1273 | [删除树节点](../../problems/delete-tree-nodes) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1254 | [统计封闭岛屿的数目](../../problems/number-of-closed-islands) | [[深度优先搜索](../depth-first-search/README.md)] | Medium | diff --git a/tag/dynamic-programming/README.md b/tag/dynamic-programming/README.md index 28ab71a2c..84453c782 100644 --- a/tag/dynamic-programming/README.md +++ b/tag/dynamic-programming/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1320 | [二指输入的的最小距离](../../problems/minimum-distance-to-type-a-word-using-two-fingers) | [[动态规划](../dynamic-programming/README.md)] | Hard | +| 1314 | [矩阵区域和](../../problems/matrix-block-sum) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 1312 | [让字符串成为回文串的最少插入次数](../../problems/minimum-insertion-steps-to-make-a-string-palindrome) | [[动态规划](../dynamic-programming/README.md)] | Hard | | 1301 | [最大得分的路径数目](../../problems/number-of-paths-with-max-score) | [[动态规划](../dynamic-programming/README.md)] | Hard | | 1289 | [下降路径最小和 II](../../problems/minimum-falling-path-sum-ii) | [[动态规划](../dynamic-programming/README.md)] | Hard | diff --git a/tag/math/README.md b/tag/math/README.md index b35d02202..7cc0c2a34 100644 --- a/tag/math/README.md +++ b/tag/math/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1317 | [将整数转换为两个无零整数的和](../../problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [[数学](../math/README.md)] | Easy | | 1307 | [口算难题](../../problems/verbal-arithmetic-puzzle) | [[数学](../math/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | | 1281 | [整数的各位积和之差](../../problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [[数学](../math/README.md)] | Easy | | 1276 | [不浪费原料的汉堡制作方案](../../problems/number-of-burgers-with-no-waste-of-ingredients) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Medium | diff --git a/tag/string/README.md b/tag/string/README.md index 976e47a4c..fb2e0f732 100644 --- a/tag/string/README.md +++ b/tag/string/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1316 | [不同的循环子字符串](../../problems/distinct-echo-substrings) | [[字符串](../string/README.md)] | Hard | | 1311 | [获取你好友已观看的视频](../../problems/get-watched-videos-by-your-friends) | [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Medium | | 1309 | [解码字母到整数映射](../../problems/decrypt-string-from-alphabet-to-integer-mapping) | [[字符串](../string/README.md)] | Easy | | 1297 | [子串的最大出现次数](../../problems/maximum-number-of-occurrences-of-a-substring) | [[位运算](../bit-manipulation/README.md)] [[字符串](../string/README.md)] | Medium | diff --git a/tag/tags.json b/tag/tags.json index 57ef282a7..07bcfd4a6 100644 --- a/tag/tags.json +++ b/tag/tags.json @@ -184,16 +184,16 @@ "Slug": "reservoir-sampling", "TranslatedName": "蓄水池抽样" }, - { - "Name": "Memoization", - "Slug": "memoization", - "TranslatedName": "记忆化" - }, { "Name": "Rolling Hash", "Slug": "rolling-hash", "TranslatedName": "Rolling Hash" }, + { + "Name": "Memoization", + "Slug": "memoization", + "TranslatedName": "记忆化" + }, { "Name": "Suffix Array", "Slug": "suffix-array", diff --git a/tag/tree/README.md b/tag/tree/README.md index 85e15669c..8a85b87d4 100644 --- a/tag/tree/README.md +++ b/tag/tree/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1315 | [祖父节点值为偶数的节点和](../../problems/sum-of-nodes-with-even-valued-grandparent) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 1305 | [两棵二叉搜索树中的所有元素](../../problems/all-elements-in-two-binary-search-trees) | [[排序](../sort/README.md)] [[树](../tree/README.md)] | Medium | | 1302 | [层数最深叶子节点的和](../../problems/deepest-leaves-sum) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 1261 | [在受污染的二叉树中查找元素](../../problems/find-elements-in-a-contaminated-binary-tree) | [[树](../tree/README.md)] [[哈希表](../hash-table/README.md)] | Medium | diff --git a/tag/union-find/README.md b/tag/union-find/README.md index 71691b39d..638ca37b7 100644 --- a/tag/union-find/README.md +++ b/tag/union-find/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1319 | [连通网络的操作次数](../../problems/number-of-operations-to-make-network-connected) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | | 1202 | [交换字符串中的元素](../../problems/smallest-string-with-swaps) | [[并查集](../union-find/README.md)] [[数组](../array/README.md)] | Medium | | 1168 | [水资源分配优化](../../problems/optimize-water-distribution-in-a-village) 🔒 | [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Hard | | 1135 | [最低成本联通所有城市](../../problems/connecting-cities-with-minimum-cost) 🔒 | [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Medium |