diff --git a/README.md b/README.md index 195daf598..32eaa84a7 100644 --- a/README.md +++ b/README.md @@ -54,9 +54,18 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1187 | [Make Array Strictly Increasing](https://leetcode.com/problems/make-array-strictly-increasing "使数组严格递增") | [Go](https://github.com/openset/leetcode/tree/master/problems/make-array-strictly-increasing) | Hard | +| 1186 | [Maximum Subarray Sum with One Deletion](https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion "删除一次得到子数组最大和") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-subarray-sum-with-one-deletion) | Medium | +| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week "一周中的第几天") | [Go](https://github.com/openset/leetcode/tree/master/problems/day-of-the-week) | Easy | +| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops "公交站间的距离") | [Go](https://github.com/openset/leetcode/tree/master/problems/distance-between-bus-stops) | Easy | +| 1183 | [Maximum Number of Ones](https://leetcode.com/problems/maximum-number-of-ones "矩阵中 1 的最大数量") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-number-of-ones) | Hard | +| 1182 | [Shortest Distance to Target Color](https://leetcode.com/problems/shortest-distance-to-target-color "与目标颜色间的最短距离") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-distance-to-target-color) | Medium | +| 1181 | [Before and After Puzzle](https://leetcode.com/problems/before-and-after-puzzle "前后拼接") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/before-and-after-puzzle) | Medium | +| 1180 | [Count Substrings with Only One Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter "统计只含单一字母的子串") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/count-substrings-with-only-one-distinct-letter) | Easy | +| 1179 | [Reformat Department Table](https://leetcode.com/problems/reformat-department-table) | [MySQL](https://github.com/openset/leetcode/tree/master/problems/reformat-department-table) | Easy | | 1178 | [Number of Valid Words for Each Puzzle](https://leetcode.com/problems/number-of-valid-words-for-each-puzzle "猜字谜") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle) | Hard | | 1177 | [Can Make Palindrome from Substring](https://leetcode.com/problems/can-make-palindrome-from-substring "构建回文串检测") | [Go](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring) | Medium | -| 1176 | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance "健身计划评估") | [Go](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | Easy | +| 1176 | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance "健身计划评估") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | Easy | | 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements "质数排列") | [Go](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements) | Easy | | 1174 | [Immediate Food Delivery II](https://leetcode.com/problems/immediate-food-delivery-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-ii) | Medium | | 1173 | [Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-i) | Easy | @@ -157,14 +166,14 @@ LeetCode Problems' Solutions | 1078 | [Occurrences After Bigram](https://leetcode.com/problems/occurrences-after-bigram "Bigram 分词") | [Go](https://github.com/openset/leetcode/tree/master/problems/occurrences-after-bigram) | Easy | | 1077 | [Project Employees III](https://leetcode.com/problems/project-employees-iii "项目员工 III") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-iii) | Medium | | 1076 | [Project Employees II](https://leetcode.com/problems/project-employees-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-ii) | Easy | -| 1075 | [Project Employees I](https://leetcode.com/problems/project-employees-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-i) | Easy | +| 1075 | [Project Employees I](https://leetcode.com/problems/project-employees-i "项目员工 I") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-i) | Easy | | 1074 | [Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target "元素和为目标值的子矩阵数量") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-submatrices-that-sum-to-target) | Hard | | 1073 | [Adding Two Negabinary Numbers](https://leetcode.com/problems/adding-two-negabinary-numbers "负二进制数相加") | [Go](https://github.com/openset/leetcode/tree/master/problems/adding-two-negabinary-numbers) | Medium | | 1072 | [Flip Columns For Maximum Number of Equal Rows](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows "按列翻转得到最大值等行数") | [Go](https://github.com/openset/leetcode/tree/master/problems/flip-columns-for-maximum-number-of-equal-rows) | Medium | | 1071 | [Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings "字符串的最大公因子") | [Go](https://github.com/openset/leetcode/tree/master/problems/greatest-common-divisor-of-strings) | Easy | | 1070 | [Product Sales Analysis III](https://leetcode.com/problems/product-sales-analysis-iii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-iii) | Medium | | 1069 | [Product Sales Analysis II](https://leetcode.com/problems/product-sales-analysis-ii "产品销售分析 II") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-ii) | Easy | -| 1068 | [Product Sales Analysis I](https://leetcode.com/problems/product-sales-analysis-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-i) | Easy | +| 1068 | [Product Sales Analysis I](https://leetcode.com/problems/product-sales-analysis-i "产品销售分析 I") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-i) | Easy | | 1067 | [Digit Count in Range](https://leetcode.com/problems/digit-count-in-range "范围内的数字计数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/digit-count-in-range) | Hard | | 1066 | [Campus Bikes II](https://leetcode.com/problems/campus-bikes-ii "校园自行车分配 II") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/campus-bikes-ii) | Medium | | 1065 | [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string "字符串的索引对") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/index-pairs-of-a-string) | Easy | @@ -295,7 +304,7 @@ LeetCode Problems' Solutions | 940 | [Distinct Subsequences II](https://leetcode.com/problems/distinct-subsequences-ii "不同的子序列 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/distinct-subsequences-ii) | Hard | | 939 | [Minimum Area Rectangle](https://leetcode.com/problems/minimum-area-rectangle "最小面积矩形") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-area-rectangle) | Medium | | 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst "二叉搜索树的范围和") | [Go](https://github.com/openset/leetcode/tree/master/problems/range-sum-of-bst) | Easy | -| 937 | [Reorder Log Files](https://leetcode.com/problems/reorder-log-files "重新排列日志文件") | [Go](https://github.com/openset/leetcode/tree/master/problems/reorder-log-files) | Easy | +| 937 | [Reorder Data in Log Files](https://leetcode.com/problems/reorder-data-in-log-files "重新排列日志文件") | [Go](https://github.com/openset/leetcode/tree/master/problems/reorder-data-in-log-files) | Easy | | 936 | [Stamping The Sequence](https://leetcode.com/problems/stamping-the-sequence "戳印序列") | [Go](https://github.com/openset/leetcode/tree/master/problems/stamping-the-sequence) | Hard | | 935 | [Knight Dialer](https://leetcode.com/problems/knight-dialer "骑士拨号器") | [Go](https://github.com/openset/leetcode/tree/master/problems/knight-dialer) | Medium | | 934 | [Shortest Bridge](https://leetcode.com/problems/shortest-bridge "最短的桥") | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-bridge) | Medium | diff --git a/problems/before-and-after-puzzle/README.md b/problems/before-and-after-puzzle/README.md new file mode 100644 index 000000000..41198589f --- /dev/null +++ b/problems/before-and-after-puzzle/README.md @@ -0,0 +1,28 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/count-substrings-with-only-one-distinct-letter "Count Substrings with Only One Distinct Letter") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/shortest-distance-to-target-color "Shortest Distance to Target Color") + +## 1181. Before and After Puzzle (Medium) + + + +### Related Topics + [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] + +### Hints +
+Hint 1 +What if you check every pair of strings (bruteforce)? +
+ +
+Hint 2 +For every two strings, check if they can form a puzzle by comparing their last and first words. +
diff --git a/problems/best-time-to-buy-and-sell-stock-ii/README.md b/problems/best-time-to-buy-and-sell-stock-ii/README.md index 4257b8cc1..a379f0e32 100644 --- a/problems/best-time-to-buy-and-sell-stock-ii/README.md +++ b/problems/best-time-to-buy-and-sell-stock-ii/README.md @@ -44,8 +44,8 @@ Explanation: In this case, no transaction is done, i.e. max profit = 0. ### Related Topics - [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)] + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] ### Similar Questions 1. [Best Time to Buy and Sell Stock](https://github.com/openset/leetcode/tree/master/problems/best-time-to-buy-and-sell-stock) (Easy) diff --git a/problems/can-make-palindrome-from-substring/README.md b/problems/can-make-palindrome-from-substring/README.md index 054f2c79c..44eabf9bf 100644 --- a/problems/can-make-palindrome-from-substring/README.md +++ b/problems/can-make-palindrome-from-substring/README.md @@ -9,7 +9,7 @@                  [Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle "Number of Valid Words for Each Puzzle") -## 5175. Can Make Palindrome from Substring (Medium) +## 1177. Can Make Palindrome from Substring (Medium)

Given a string s, we make queries on substrings of s.

diff --git a/problems/count-substrings-with-only-one-distinct-letter/README.md b/problems/count-substrings-with-only-one-distinct-letter/README.md new file mode 100644 index 000000000..a17c039e6 --- /dev/null +++ b/problems/count-substrings-with-only-one-distinct-letter/README.md @@ -0,0 +1,34 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/reformat-department-table "Reformat Department Table") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/before-and-after-puzzle "Before and After Puzzle") + +## 1180. Count Substrings with Only One Distinct Letter (Easy) + + + +### Related Topics + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] + [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] + +### Hints +
+Hint 1 +What if we divide the string into substrings containing only one distinct character with maximal lengths? +
+ +
+Hint 2 +Now that you have sub-strings with only one distinct character, Try to come up with a formula that counts the number of its sub-strings. +
+ +
+Hint 3 +Alternatively, Observe that the constraints are small so you can use brute force. +
diff --git a/problems/day-of-the-week/README.md b/problems/day-of-the-week/README.md new file mode 100644 index 000000000..370666eee --- /dev/null +++ b/problems/day-of-the-week/README.md @@ -0,0 +1,66 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/distance-between-bus-stops "Distance Between Bus Stops") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/maximum-subarray-sum-with-one-deletion "Maximum Subarray Sum with One Deletion") + +## 1185. Day of the Week (Easy) + +

Given a date, return the corresponding day of the week for that date.

+ +

The input is given as three integers representing the day, month and year respectively.

+ +

Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

+ +

 

+

Example 1:

+ +
+Input: day = 31, month = 8, year = 2019
+Output: "Saturday"
+
+ +

Example 2:

+ +
+Input: day = 18, month = 7, year = 1999
+Output: "Sunday"
+
+ +

Example 3:

+ +
+Input: day = 15, month = 8, year = 1993
+Output: "Sunday"
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] + +### Hints +
+Hint 1 +Sum up the number of days for the years before the given year. +
+ +
+Hint 2 +Handle the case of a leap year. +
+ +
+Hint 3 +Find the number of days for each month of the given year. +
diff --git a/problems/diet-plan-performance/README.md b/problems/diet-plan-performance/README.md index 26421deaf..7d81903c3 100644 --- a/problems/diet-plan-performance/README.md +++ b/problems/diet-plan-performance/README.md @@ -9,7 +9,7 @@                  [Next >](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring "Can Make Palindrome from Substring") -## 5174. Diet Plan Performance (Easy) +## 1176. Diet Plan Performance (Easy)

A dieter consumes calories[i] calories on the i-th day.  For every consecutive sequence of k days, they look at T, the total calories consumed during that sequence of k days:

@@ -44,7 +44,7 @@
 Input: calories = [6,5,0,0], k = 2, lower = 1, upper = 5
 Output: 0
-Explaination: calories[0] + calories[1] > upper, calories[2] + calories[3] < lower, total points = 0.
+Explaination: calories[0] + calories[1] > upper, lower <= calories[1] + calories[2] <= upper, calories[2] + calories[3] < lower, total points = 0.
 

 

diff --git a/problems/distance-between-bus-stops/README.md b/problems/distance-between-bus-stops/README.md new file mode 100644 index 000000000..9adde3bd9 --- /dev/null +++ b/problems/distance-between-bus-stops/README.md @@ -0,0 +1,71 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/maximum-number-of-ones "Maximum Number of Ones") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/day-of-the-week "Day of the Week") + +## 1184. Distance Between Bus Stops (Easy) + +

A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.

+ +

The bus goes along both directions i.e. clockwise and counterclockwise.

+ +

Return the shortest distance between the given start and destination stops.

+ +

 

+

Example 1:

+ +

+ +
+Input: distance = [1,2,3,4], start = 0, destination = 1
+Output: 1
+Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.
+ +

 

+ +

Example 2:

+ +

+ +
+Input: distance = [1,2,3,4], start = 0, destination = 2
+Output: 3
+Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.
+
+ +

 

+ +

Example 3:

+ +

+ +
+Input: distance = [1,2,3,4], start = 0, destination = 3
+Output: 4
+Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] + +### Hints +
+Hint 1 +Find the distance between the two stops if the bus moved in clockwise or counterclockwise directions. +
diff --git a/problems/insertion-sort-list/README.md b/problems/insertion-sort-list/README.md index 72eff798a..ccb768d9d 100644 --- a/problems/insertion-sort-list/README.md +++ b/problems/insertion-sort-list/README.md @@ -48,8 +48,8 @@ With each iteration one element (red) is removed from the input data and inserte ### Related Topics - [[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)] [[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)] + [[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)] ### Similar Questions 1. [Sort List](https://github.com/openset/leetcode/tree/master/problems/sort-list) (Medium) diff --git a/problems/longest-consecutive-sequence/README.md b/problems/longest-consecutive-sequence/README.md index 257addc45..43b0bd141 100644 --- a/problems/longest-consecutive-sequence/README.md +++ b/problems/longest-consecutive-sequence/README.md @@ -24,8 +24,8 @@ ### Related Topics - [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] ### Similar Questions 1. [Binary Tree Longest Consecutive Sequence](https://github.com/openset/leetcode/tree/master/problems/binary-tree-longest-consecutive-sequence) (Medium) diff --git a/problems/majority-element/README.md b/problems/majority-element/README.md index f274178fa..8f50acbf8 100644 --- a/problems/majority-element/README.md +++ b/problems/majority-element/README.md @@ -29,9 +29,9 @@ ### Related Topics + [[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Divide and Conquer](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md)] - [[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] ### Similar Questions 1. [Majority Element II](https://github.com/openset/leetcode/tree/master/problems/majority-element-ii) (Medium) diff --git a/problems/make-array-strictly-increasing/README.md b/problems/make-array-strictly-increasing/README.md new file mode 100644 index 000000000..3031267a9 --- /dev/null +++ b/problems/make-array-strictly-increasing/README.md @@ -0,0 +1,66 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/maximum-subarray-sum-with-one-deletion "Maximum Subarray Sum with One Deletion") +                 +Next > + +## 1187. Make Array Strictly Increasing (Hard) + +

Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.

+ +

In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i] = arr2[j].

+ +

If there is no way to make arr1 strictly increasing, return -1.

+ +

 

+

Example 1:

+ +
+Input: arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]
+Output: 1
+Explanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].
+
+ +

Example 2:

+ +
+Input: arr1 = [1,5,3,6,7], arr2 = [4,3,1]
+Output: 2
+Explanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].
+
+ +

Example 3:

+ +
+Input: arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]
+Output: -1
+Explanation: You can't make arr1 strictly increasing.
+ +

 

+

Constraints:

+ + + +

 

+ +### Related Topics + [[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +Use dynamic programming. +
+ +
+Hint 2 +The state would be the index in arr1 and the index of the previous element in arr2 after sorting it and removing duplicates. +
diff --git a/problems/maximum-number-of-ones/README.md b/problems/maximum-number-of-ones/README.md new file mode 100644 index 000000000..60c4ff839 --- /dev/null +++ b/problems/maximum-number-of-ones/README.md @@ -0,0 +1,39 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/shortest-distance-to-target-color "Shortest Distance to Target Color") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/distance-between-bus-stops "Distance Between Bus Stops") + +## 1183. Maximum Number of Ones (Hard) + + + +### Related Topics + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] + [[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)] + +### Hints +
+Hint 1 +Think of a greedy mathematical solution. +
+ +
+Hint 2 +Say you choose to set some cell (i, j) to 1, all cells (x, y) such that i % sideLength == x % sideLength and j % sideLength == y % sideLength can also be set to 1 without increasing the max number of ones in a sub-matrix. +
+ +
+Hint 3 +In one move, choose to set all the cells with some modulus (i % sideLength, j % sideLength) to 1. +
+ +
+Hint 4 +Choose the cells with max frequency. +
diff --git a/problems/maximum-subarray-sum-with-one-deletion/README.md b/problems/maximum-subarray-sum-with-one-deletion/README.md new file mode 100644 index 000000000..9bdd7636f --- /dev/null +++ b/problems/maximum-subarray-sum-with-one-deletion/README.md @@ -0,0 +1,67 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/day-of-the-week "Day of the Week") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/make-array-strictly-increasing "Make Array Strictly Increasing") + +## 1186. Maximum Subarray Sum with One Deletion (Medium) + +

Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible.

+ +

Note that the subarray needs to be non-empty after deleting one element.

+ +

 

+

Example 1:

+ +
+Input: arr = [1,-2,0,3]
+Output: 4
+Explanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.
+ +

Example 2:

+ +
+Input: arr = [1,-2,-2,3]
+Output: 3
+Explanation: We just choose [3] and it's the maximum sum.
+
+ +

Example 3:

+ +
+Input: arr = [-1,-1,-1,-1]
+Output: -1
+Explanation: The final subarray needs to be non-empty. You can't choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +How to solve this problem if no deletions are allowed ? +
+ +
+Hint 2 +Try deleting each element and find the maximum subarray sum to both sides of that element. +
+ +
+Hint 3 +To do that efficiently, use the idea of Kadane's algorithm. +
diff --git a/problems/number-of-valid-words-for-each-puzzle/README.md b/problems/number-of-valid-words-for-each-puzzle/README.md index 3026be55d..8b5e49eee 100644 --- a/problems/number-of-valid-words-for-each-puzzle/README.md +++ b/problems/number-of-valid-words-for-each-puzzle/README.md @@ -7,9 +7,9 @@ [< Previous](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring "Can Make Palindrome from Substring")                  -Next > +[Next >](https://github.com/openset/leetcode/tree/master/problems/reformat-department-table "Reformat Department Table") -## 5176. Number of Valid Words for Each Puzzle (Hard) +## 1178. Number of Valid Words for Each Puzzle (Hard) With respect to a given puzzle string, a word is valid if both the following conditions are satisfied: ### Related Topics + [[Breadth-first Search](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)] [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] [[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] - [[Breadth-first Search](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)] ### Similar Questions 1. [Word Ladder](https://github.com/openset/leetcode/tree/master/problems/word-ladder) (Medium) diff --git a/readme/301-600.md b/readme/301-600.md index d53acd694..d9fa46624 100644 --- a/readme/301-600.md +++ b/readme/301-600.md @@ -264,7 +264,7 @@ LeetCode Problems' Solutions | 508 | [Most Frequent Subtree Sum](https://leetcode.com/problems/most-frequent-subtree-sum "出现次数最多的子树元素和") | [Go](https://github.com/openset/leetcode/tree/master/problems/most-frequent-subtree-sum) | Medium | | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number "斐波那契数") | [Go](https://github.com/openset/leetcode/tree/master/problems/fibonacci-number) | Easy | | 510 | [Inorder Successor in BST II](https://leetcode.com/problems/inorder-successor-in-bst-ii "二叉搜索树中的中序后继 II") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/inorder-successor-in-bst-ii) | Medium | -| 511 | [Game Play Analysis I](https://leetcode.com/problems/game-play-analysis-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/game-play-analysis-i) | Easy | +| 511 | [Game Play Analysis I](https://leetcode.com/problems/game-play-analysis-i "游戏玩法分析 I") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/game-play-analysis-i) | Easy | | 512 | [Game Play Analysis II](https://leetcode.com/problems/game-play-analysis-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/game-play-analysis-ii) | Easy | | 513 | [Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value "找树左下角的值") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-bottom-left-tree-value) | Medium | | 514 | [Freedom Trail](https://leetcode.com/problems/freedom-trail "自由之路") | [Go](https://github.com/openset/leetcode/tree/master/problems/freedom-trail) | Hard | diff --git a/tag/array/README.md b/tag/array/README.md index 39274b492..c795b9fb2 100644 --- a/tag/array/README.md +++ b/tag/array/README.md @@ -9,8 +9,8 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | -| 5175 | [构建回文串检测](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Medium | -| 5174 | [健身计划评估](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Easy | +| 1177 | [构建回文串检测](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Medium | +| 1176 | [健身计划评估](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Easy | | 1170 | [比较字符串最小字母出现频次](https://github.com/openset/leetcode/tree/master/problems/compare-strings-by-frequency-of-the-smallest-character) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Easy | | 1169 | [查询无效交易](https://github.com/openset/leetcode/tree/master/problems/invalid-transactions) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Easy | | 1160 | [拼写单词](https://github.com/openset/leetcode/tree/master/problems/find-words-that-can-be-formed-by-characters) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Easy | diff --git a/tag/bit-manipulation/README.md b/tag/bit-manipulation/README.md index ad564e63a..98b217ee5 100644 --- a/tag/bit-manipulation/README.md +++ b/tag/bit-manipulation/README.md @@ -9,7 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | -| 5176 | [猜字谜](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle) | [[位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Hard | +| 1178 | [猜字谜](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle) | [[位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Hard | | 1125 | [最小的必要团队](https://github.com/openset/leetcode/tree/master/problems/smallest-sufficient-team) | [[位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Hard | | 898 | [子数组按位或操作](https://github.com/openset/leetcode/tree/master/problems/bitwise-ors-of-subarrays) | [[位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Medium | | 784 | [字母大小写全排列](https://github.com/openset/leetcode/tree/master/problems/letter-case-permutation) | [[位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[回溯算法](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] | Easy | diff --git a/tag/hash-table/README.md b/tag/hash-table/README.md index 2bc56f593..e420037f6 100644 --- a/tag/hash-table/README.md +++ b/tag/hash-table/README.md @@ -9,7 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | -| 5176 | [猜字谜](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle) | [[位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Hard | +| 1178 | [猜字谜](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle) | [[位运算](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Hard | | 1166 | [设计文件系统](https://github.com/openset/leetcode/tree/master/problems/design-file-system) 🔒 | [[设计](https://github.com/openset/leetcode/tree/master/tag/design/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Medium | | 1160 | [拼写单词](https://github.com/openset/leetcode/tree/master/problems/find-words-that-can-be-formed-by-characters) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Easy | | 1152 | [用户网站访问行为分析](https://github.com/openset/leetcode/tree/master/problems/analyze-user-website-visit-pattern) 🔒 | [[排序](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)] [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Medium | diff --git a/tag/math/README.md b/tag/math/README.md index 51fce712d..cec69e8fa 100644 --- a/tag/math/README.md +++ b/tag/math/README.md @@ -9,7 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | -| 5173 | [质数排列](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | Easy | +| 1175 | [质数排列](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | Easy | | 1134 | [阿姆斯特朗数](https://github.com/openset/leetcode/tree/master/problems/armstrong-number) 🔒 | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | Easy | | 1121 | [将数组分成几个递增序列](https://github.com/openset/leetcode/tree/master/problems/divide-array-into-increasing-sequences) 🔒 | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | Hard | | 1104 | [二叉树寻路](https://github.com/openset/leetcode/tree/master/problems/path-in-zigzag-labelled-binary-tree) | [[树](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)] [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | Medium | diff --git a/tag/sliding-window/README.md b/tag/sliding-window/README.md index c7e5a4f8f..d18dd0a4f 100644 --- a/tag/sliding-window/README.md +++ b/tag/sliding-window/README.md @@ -9,7 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | -| 5174 | [健身计划评估](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Easy | +| 1176 | [健身计划评估](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Easy | | 1151 | [最少交换次数来组合所有的 1](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-group-all-1s-together) 🔒 | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Medium | | 1100 | [长度为 K 的无重复字符子串](https://github.com/openset/leetcode/tree/master/problems/find-k-length-substrings-with-no-repeated-characters) 🔒 | [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Medium | | 1074 | [元素和为目标值的子矩阵数量](https://github.com/openset/leetcode/tree/master/problems/number-of-submatrices-that-sum-to-target) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Hard | diff --git a/tag/string/README.md b/tag/string/README.md index 346572595..470117573 100644 --- a/tag/string/README.md +++ b/tag/string/README.md @@ -9,7 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | -| 5175 | [构建回文串检测](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Medium | +| 1177 | [构建回文串检测](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Medium | | 1170 | [比较字符串最小字母出现频次](https://github.com/openset/leetcode/tree/master/problems/compare-strings-by-frequency-of-the-smallest-character) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Easy | | 1169 | [查询无效交易](https://github.com/openset/leetcode/tree/master/problems/invalid-transactions) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Easy | | 1165 | [单行键盘](https://github.com/openset/leetcode/tree/master/problems/single-row-keyboard) 🔒 | [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Easy |