diff --git a/README.md b/README.md index f9850dd2c..657d3855c 100644 --- a/README.md +++ b/README.md @@ -62,12 +62,22 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1220 | [Count Vowels Permutation](https://leetcode.com/problems/count-vowels-permutation "统计元音字母序列的数目") | [Go](https://github.com/openset/leetcode/tree/master/problems/count-vowels-permutation) | Hard | +| 1219 | [Path with Maximum Gold](https://leetcode.com/problems/path-with-maximum-gold "黄金矿工") | [Go](https://github.com/openset/leetcode/tree/master/problems/path-with-maximum-gold) | Medium | +| 1218 | [Longest Arithmetic Subsequence of Given Difference](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference "最长定差子序列") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-arithmetic-subsequence-of-given-difference) | Medium | +| 1217 | [Play with Chips](https://leetcode.com/problems/play-with-chips "玩筹码") | [Go](https://github.com/openset/leetcode/tree/master/problems/play-with-chips) | Easy | +| 1216 | [Valid Palindrome III](https://leetcode.com/problems/valid-palindrome-iii "验证回文字符串 III") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/valid-palindrome-iii) | Hard | +| 1215 | [Stepping Numbers](https://leetcode.com/problems/stepping-numbers "步进数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/stepping-numbers) | Medium | +| 1214 | [Two Sum BSTs](https://leetcode.com/problems/two-sum-bsts "查找两棵二叉搜索树之和") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/two-sum-bsts) | Medium | +| 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays "三个有序数组的交集") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/intersection-of-three-sorted-arrays) | Easy | +| 1212 | [Team Scores in Football Tournament](https://leetcode.com/problems/team-scores-in-football-tournament) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/team-scores-in-football-tournament) | Medium | +| 1211 | [Queries Quality and Percentage](https://leetcode.com/problems/queries-quality-and-percentage) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/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](https://github.com/openset/leetcode/tree/master/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](https://github.com/openset/leetcode/tree/master/problems/remove-all-adjacent-duplicates-in-string-ii) | Medium | | 1208 | [Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget "尽可能使字符串相等") | [Go](https://github.com/openset/leetcode/tree/master/problems/get-equal-substrings-within-budget) | Medium | | 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences "独一无二的出现次数") | [Go](https://github.com/openset/leetcode/tree/master/problems/unique-number-of-occurrences) | Easy | -| 1206 | [Design Skiplist](https://leetcode.com/problems/design-skiplist) | [Go](https://github.com/openset/leetcode/tree/master/problems/design-skiplist) | Hard | -| 1205 | [Monthly Transactions II](https://leetcode.com/problems/monthly-transactions-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/monthly-transactions-ii) | Medium | +| 1206 | [Design Skiplist](https://leetcode.com/problems/design-skiplist "设计跳表") | [Go](https://github.com/openset/leetcode/tree/master/problems/design-skiplist) | Hard | +| 1205 | [Monthly Transactions II](https://leetcode.com/problems/monthly-transactions-ii "每月交易II") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/monthly-transactions-ii) | Medium | | 1204 | [Last Person to Fit in the Elevator](https://leetcode.com/problems/last-person-to-fit-in-the-elevator) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/last-person-to-fit-in-the-elevator) | Medium | | 1203 | [Sort Items by Groups Respecting Dependencies](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies "项目管理") | [Go](https://github.com/openset/leetcode/tree/master/problems/sort-items-by-groups-respecting-dependencies) | Hard | | 1202 | [Smallest String With Swaps](https://leetcode.com/problems/smallest-string-with-swaps "交换字符串中的元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/smallest-string-with-swaps) | Medium | @@ -78,7 +88,7 @@ LeetCode Problems' Solutions | 1197 | [Minimum Knight Moves](https://leetcode.com/problems/minimum-knight-moves "进击的骑士") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-knight-moves) | Medium | | 1196 | [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket "最多可以买到的苹果数量") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/how-many-apples-can-you-put-into-the-basket) | Easy | | 1195 | [Fizz Buzz Multithreaded](https://leetcode.com/problems/fizz-buzz-multithreaded "交替打印字符串") | [Go](https://github.com/openset/leetcode/tree/master/problems/fizz-buzz-multithreaded) | Medium | -| 1194 | [Tournament Winners](https://leetcode.com/problems/tournament-winners) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/tournament-winners) | Hard | +| 1194 | [Tournament Winners](https://leetcode.com/problems/tournament-winners "锦标赛优胜者") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/tournament-winners) | Hard | | 1193 | [Monthly Transactions I](https://leetcode.com/problems/monthly-transactions-i "每月交易 I") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/monthly-transactions-i) | Medium | | 1192 | [Critical Connections in a Network](https://leetcode.com/problems/critical-connections-in-a-network "查找集群内的「关键连接」") | [Go](https://github.com/openset/leetcode/tree/master/problems/critical-connections-in-a-network) | Hard | | 1191 | [K-Concatenation Maximum Sum](https://leetcode.com/problems/k-concatenation-maximum-sum "K 次串联后最大子数组之和") | [Go](https://github.com/openset/leetcode/tree/master/problems/k-concatenation-maximum-sum) | Medium | @@ -175,7 +185,7 @@ LeetCode Problems' Solutions | 1100 | [Find K-Length Substrings With No Repeated Characters](https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters "长度为 K 的无重复字符子串") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/find-k-length-substrings-with-no-repeated-characters) | Medium | | 1099 | [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k "小于 K 的两数之和") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/two-sum-less-than-k) | Easy | | 1098 | [Unpopular Books](https://leetcode.com/problems/unpopular-books "小众书籍") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/unpopular-books) | Medium | -| 1097 | [Game Play Analysis V](https://leetcode.com/problems/game-play-analysis-v) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/game-play-analysis-v) | Hard | +| 1097 | [Game Play Analysis V](https://leetcode.com/problems/game-play-analysis-v "游戏玩法分析 V") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/game-play-analysis-v) | Hard | | 1096 | [Brace Expansion II](https://leetcode.com/problems/brace-expansion-ii "花括号展开 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/brace-expansion-ii) | Hard | | 1095 | [Find in Mountain Array](https://leetcode.com/problems/find-in-mountain-array "山脉数组中查找目标值") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array) | Hard | | 1094 | [Car Pooling](https://leetcode.com/problems/car-pooling "拼车") | [Go](https://github.com/openset/leetcode/tree/master/problems/car-pooling) | Medium | diff --git a/problems/count-vowels-permutation/README.md b/problems/count-vowels-permutation/README.md new file mode 100644 index 000000000..bfeb1988a --- /dev/null +++ b/problems/count-vowels-permutation/README.md @@ -0,0 +1,71 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/path-with-maximum-gold "Path with Maximum Gold") +                 +Next > + +## [5216. Count Vowels Permutation (Hard)](https://leetcode.com/problems/count-vowels-permutation "统计元音字母序列的数目") + +

Given an integer n, your task is to count how many strings of length n can be formed under the following rules:

+ + + +

Since the answer may be too large, return it modulo 10^9 + 7.

+ +

 

+

Example 1:

+ +
+Input: n = 1
+Output: 5
+Explanation: All possible strings are: "a", "e", "i" , "o" and "u".
+
+ +

Example 2:

+ +
+Input: n = 2
+Output: 10
+Explanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".
+
+ +

Example 3: 

+ +
+Input: n = 5
+Output: 68
+ +

 

+

Constraints:

+ + + +### Hints +
+Hint 1 +Use dynamic programming. +
+ +
+Hint 2 +Let dp[i][j] be the number of strings of length i that ends with the j-th vowel. +
+ +
+Hint 3 +Deduce the recurrence from the given relations between vowels. +
diff --git a/problems/design-skiplist/README.md b/problems/design-skiplist/README.md index 354c0ce2c..955122928 100644 --- a/problems/design-skiplist/README.md +++ b/problems/design-skiplist/README.md @@ -9,7 +9,7 @@                  [Next >](https://github.com/openset/leetcode/tree/master/problems/unique-number-of-occurrences "Unique Number of Occurrences") -## [1206. Design Skiplist (Hard)](https://leetcode.com/problems/design-skiplist "") +## [1206. Design Skiplist (Hard)](https://leetcode.com/problems/design-skiplist "设计跳表")

Design a Skiplist without using any built-in libraries.

diff --git a/problems/game-play-analysis-v/README.md b/problems/game-play-analysis-v/README.md index 68bc6787c..212fea034 100644 --- a/problems/game-play-analysis-v/README.md +++ b/problems/game-play-analysis-v/README.md @@ -9,7 +9,7 @@                  [Next >](https://github.com/openset/leetcode/tree/master/problems/unpopular-books "Unpopular Books") -## [1097. Game Play Analysis V (Hard)](https://leetcode.com/problems/game-play-analysis-v "") +## [1097. Game Play Analysis V (Hard)](https://leetcode.com/problems/game-play-analysis-v "游戏玩法分析 V") diff --git a/problems/intersection-of-three-sorted-arrays/README.md b/problems/intersection-of-three-sorted-arrays/README.md new file mode 100644 index 000000000..bf2a38a6e --- /dev/null +++ b/problems/intersection-of-three-sorted-arrays/README.md @@ -0,0 +1,49 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/team-scores-in-football-tournament "Team Scores in Football Tournament") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/two-sum-bsts "Two Sum BSTs") + +## [5079. Intersection of Three Sorted Arrays (Easy)](https://leetcode.com/problems/intersection-of-three-sorted-arrays "三个有序数组的交集") + +

Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.

+ +

 

+

Example 1:

+ +
+Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]
+Output: [1,5]
+Explanation: Only 1 and 5 appeared in the three arrays.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] + [[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] + +### Similar Questions + 1. [Intersection of Two Arrays](https://github.com/openset/leetcode/tree/master/problems/intersection-of-two-arrays) (Easy) + +### Hints +
+Hint 1 +Count the frequency of all elements in the three arrays. +
+ +
+Hint 2 +The elements that appeared in all the arrays would have a frequency of 3. +
diff --git a/problems/intersection-of-two-arrays/README.md b/problems/intersection-of-two-arrays/README.md index c12adb21c..503266cff 100644 --- a/problems/intersection-of-two-arrays/README.md +++ b/problems/intersection-of-two-arrays/README.md @@ -45,3 +45,4 @@ ### Similar Questions 1. [Intersection of Two Arrays II](https://github.com/openset/leetcode/tree/master/problems/intersection-of-two-arrays-ii) (Easy) + 1. [Intersection of Three Sorted Arrays](https://github.com/openset/leetcode/tree/master/problems/intersection-of-three-sorted-arrays) (Easy) diff --git a/problems/longest-arithmetic-subsequence-of-given-difference/README.md b/problems/longest-arithmetic-subsequence-of-given-difference/README.md new file mode 100644 index 000000000..fe73cf40d --- /dev/null +++ b/problems/longest-arithmetic-subsequence-of-given-difference/README.md @@ -0,0 +1,46 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/play-with-chips "Play with Chips") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/path-with-maximum-gold "Path with Maximum Gold") + +## [5214. Longest Arithmetic Subsequence of Given Difference (Medium)](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference "最长定差子序列") + +

Given an integer array arr and an integer difference, return the length of the longest arithmetic subsequence in arr such that the difference between adjacent elements in the subsequence equals difference.

+ +

 

+

Example 1:

+ +
+Input: arr = [1,2,3,4], difference = 1
+Output: 4
+Explanation: The longest arithmetic subsequence is [1,2,3,4].
+ +

Example 2:

+ +
+Input: arr = [1,3,5,7], difference = 1
+Output: 1
+Explanation: The longest arithmetic subsequence is any single element.
+
+ +

Example 3:

+ +
+Input: arr = [1,5,7,8,5,3,4,2,1], difference = -2
+Output: 4
+Explanation: The longest arithmetic subsequence is [7,5,3,1].
+
+ +

 

+

Constraints:

+ + diff --git a/problems/minimum-moves-to-reach-target-with-rotations/README.md b/problems/minimum-moves-to-reach-target-with-rotations/README.md index c9e6da103..124b9e918 100644 --- a/problems/minimum-moves-to-reach-target-with-rotations/README.md +++ b/problems/minimum-moves-to-reach-target-with-rotations/README.md @@ -7,7 +7,7 @@ [< Previous](https://github.com/openset/leetcode/tree/master/problems/remove-all-adjacent-duplicates-in-string-ii "Remove All Adjacent Duplicates in String II")                  -Next > +[Next >](https://github.com/openset/leetcode/tree/master/problems/queries-quality-and-percentage "Queries Quality and Percentage") ## [5208. Minimum Moves to Reach Target with Rotations (Hard)](https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations "穿过迷宫的最少移动次数") diff --git a/problems/monthly-transactions-ii/README.md b/problems/monthly-transactions-ii/README.md index 11c03a08b..e4203b140 100644 --- a/problems/monthly-transactions-ii/README.md +++ b/problems/monthly-transactions-ii/README.md @@ -9,6 +9,6 @@                  [Next >](https://github.com/openset/leetcode/tree/master/problems/design-skiplist "Design Skiplist") -## [1205. Monthly Transactions II (Medium)](https://leetcode.com/problems/monthly-transactions-ii "") +## [1205. Monthly Transactions II (Medium)](https://leetcode.com/problems/monthly-transactions-ii "每月交易II") diff --git a/problems/moving-average-from-data-stream/README.md b/problems/moving-average-from-data-stream/README.md index f403b390c..42d99a260 100644 --- a/problems/moving-average-from-data-stream/README.md +++ b/problems/moving-average-from-data-stream/README.md @@ -11,7 +11,19 @@ ## [346. Moving Average from Data Stream (Easy)](https://leetcode.com/problems/moving-average-from-data-stream "数据流中的移动平均值") +

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

+

Example:

+ +
+MovingAverage m = new MovingAverage(3);
+m.next(1) = 1
+m.next(10) = (1 + 10) / 2
+m.next(3) = (1 + 10 + 3) / 3
+m.next(5) = (10 + 3 + 5) / 3
+
+ +

 

### Related Topics [[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)] diff --git a/problems/path-with-maximum-gold/README.md b/problems/path-with-maximum-gold/README.md new file mode 100644 index 000000000..c14efd654 --- /dev/null +++ b/problems/path-with-maximum-gold/README.md @@ -0,0 +1,60 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/longest-arithmetic-subsequence-of-given-difference "Longest Arithmetic Subsequence of Given Difference") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/count-vowels-permutation "Count Vowels Permutation") + +## [5215. Path with Maximum Gold (Medium)](https://leetcode.com/problems/path-with-maximum-gold "黄金矿工") + +

In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.

+ +

Return the maximum amount of gold you can collect under the conditions:

+ + + +

 

+

Example 1:

+ +
+Input: grid = [[0,6,0],[5,8,7],[0,9,0]]
+Output: 24
+Explanation:
+[[0,6,0],
+ [5,8,7],
+ [0,9,0]]
+Path to get the maximum gold, 9 -> 8 -> 7.
+
+ +

Example 2:

+ +
+Input: grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]
+Output: 28
+Explanation:
+[[1,0,7],
+ [2,0,6],
+ [3,4,5],
+ [0,3,0],
+ [9,0,20]]
+Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.
+
+ +

 

+

Constraints:

+ + diff --git a/problems/play-with-chips/README.md b/problems/play-with-chips/README.md new file mode 100644 index 000000000..4c513dfaa --- /dev/null +++ b/problems/play-with-chips/README.md @@ -0,0 +1,50 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/valid-palindrome-iii "Valid Palindrome III") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/longest-arithmetic-subsequence-of-given-difference "Longest Arithmetic Subsequence of Given Difference") + +## [5213. Play with Chips (Easy)](https://leetcode.com/problems/play-with-chips "玩筹码") + +

You have the positions of some chips on the number line.

+ +

You can perform any of the two following types of moves any number of times (possibly zero) on any chip:

+ + + +

There can be two or more chips at the same position initially.

+ +

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

+ +

 

+

Example 1:

+ +
+Input: chips = [1,2,3]
+Output: 1
+Explanation: Second chip will be moved to positon 3 with cost 1. First chip will be moved to position 3 with cost 0. Total cost is 1.
+
+ +

Example 2:

+ +
+Input: chips = [2,2,2,3,3]
+Output: 2
+Explanation: Both fourth and fifth chip will be moved to position two with cost 1. Total minimum cost will be 2.
+
+ +

 

+

Constraints:

+ + diff --git a/problems/queries-quality-and-percentage/README.md b/problems/queries-quality-and-percentage/README.md new file mode 100644 index 000000000..1500f18fd --- /dev/null +++ b/problems/queries-quality-and-percentage/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-moves-to-reach-target-with-rotations "Minimum Moves to Reach Target with Rotations") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/team-scores-in-football-tournament "Team Scores in Football Tournament") + +## [1211. Queries Quality and Percentage (Easy)](https://leetcode.com/problems/queries-quality-and-percentage "") + + diff --git a/problems/queries-quality-and-percentage/mysql_schemas.sql b/problems/queries-quality-and-percentage/mysql_schemas.sql new file mode 100644 index 000000000..01ae2d169 --- /dev/null +++ b/problems/queries-quality-and-percentage/mysql_schemas.sql @@ -0,0 +1,8 @@ +Create table If Not Exists Queries (query_name varchar(30), result varchar(50), position int, rating int); +Truncate table Queries; +insert into Queries (query_name, result, position, rating) values ('Dog', 'Golden Retriever', '1', '5'); +insert into Queries (query_name, result, position, rating) values ('Dog', 'German Shepherd', '2', '5'); +insert into Queries (query_name, result, position, rating) values ('Dog', 'Mule', '200', '1'); +insert into Queries (query_name, result, position, rating) values ('Cat', 'Shirazi', '5', '2'); +insert into Queries (query_name, result, position, rating) values ('Cat', 'Siamese', '3', '3'); +insert into Queries (query_name, result, position, rating) values ('Cat', 'Sphynx', '7', '4'); diff --git a/problems/smallest-string-with-swaps/README.md b/problems/smallest-string-with-swaps/README.md index 57b52e7d3..388dfaf7c 100644 --- a/problems/smallest-string-with-swaps/README.md +++ b/problems/smallest-string-with-swaps/README.md @@ -47,7 +47,6 @@ Swap s[1] and s[2], s = "abcd" Swap s[0] and s[1], s = "bca" Swap s[1] and s[2], s = "bac" Swap s[0] and s[1], s = "abc" -

 

diff --git a/problems/sort-items-by-groups-respecting-dependencies/README.md b/problems/sort-items-by-groups-respecting-dependencies/README.md index 764871cb9..3971f9c37 100644 --- a/problems/sort-items-by-groups-respecting-dependencies/README.md +++ b/problems/sort-items-by-groups-respecting-dependencies/README.md @@ -38,7 +38,6 @@ Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]] Output: [] Explanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list. -

 

diff --git a/problems/stepping-numbers/README.md b/problems/stepping-numbers/README.md new file mode 100644 index 000000000..ca326c32b --- /dev/null +++ b/problems/stepping-numbers/README.md @@ -0,0 +1,47 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/two-sum-bsts "Two Sum BSTs") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/valid-palindrome-iii "Valid Palindrome III") + +## [5081. Stepping Numbers (Medium)](https://leetcode.com/problems/stepping-numbers "步进数") + +

A Stepping Number is an integer such that all of its adjacent digits have an absolute difference of exactly 1. For example, 321 is a Stepping Number while 421 is not.

+ +

Given two integers low and high, find and return a sorted list of all the Stepping Numbers in the range [low, high] inclusive.

+ +

 

+

Example 1:

+
Input: low = 0, high = 21
+Output: [0,1,2,3,4,5,6,7,8,9,10,12,21]
+
+

 

+

Constraints:

+ + + +### Related Topics + [[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] + +### Hints +
+Hint 1 +Try to generate the numbers using recursion. +
+ +
+Hint 2 +In one step in the recursion, add a valid digit to the right of the current number. +
+ +
+Hint 3 +Save the number if it's in the range between low and high. +
diff --git a/problems/team-scores-in-football-tournament/README.md b/problems/team-scores-in-football-tournament/README.md new file mode 100644 index 000000000..2f719ca6a --- /dev/null +++ b/problems/team-scores-in-football-tournament/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/queries-quality-and-percentage "Queries Quality and Percentage") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/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 "") + + diff --git a/problems/team-scores-in-football-tournament/mysql_schemas.sql b/problems/team-scores-in-football-tournament/mysql_schemas.sql new file mode 100644 index 000000000..978263cbe --- /dev/null +++ b/problems/team-scores-in-football-tournament/mysql_schemas.sql @@ -0,0 +1,14 @@ +Create table If Not Exists Teams (team_id int, team_name varchar(30)); +Create table If Not Exists Matches (match_id int, host_team int, guest_team int, host_goals int, guest_goals int); +Truncate table Teams; +insert into Teams (team_id, team_name) values ('10', 'Leetcode FC'); +insert into Teams (team_id, team_name) values ('20', 'NewYork FC'); +insert into Teams (team_id, team_name) values ('30', 'Atlanta FC'); +insert into Teams (team_id, team_name) values ('40', 'Chicago FC'); +insert into Teams (team_id, team_name) values ('50', 'Toronto FC'); +Truncate table Matches; +insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('1', '10', '20', '30', '0'); +insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('2', '30', '10', '2', '2'); +insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('3', '10', '50', '5', '1'); +insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('4', '20', '30', '1', '0'); +insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('5', '50', '30', '1', '0'); diff --git a/problems/tournament-winners/README.md b/problems/tournament-winners/README.md index d93068427..3749f6abc 100644 --- a/problems/tournament-winners/README.md +++ b/problems/tournament-winners/README.md @@ -9,6 +9,6 @@                  [Next >](https://github.com/openset/leetcode/tree/master/problems/fizz-buzz-multithreaded "Fizz Buzz Multithreaded") -## [1194. Tournament Winners (Hard)](https://leetcode.com/problems/tournament-winners "") +## [1194. Tournament Winners (Hard)](https://leetcode.com/problems/tournament-winners "锦标赛优胜者") diff --git a/problems/two-sum-bsts/README.md b/problems/two-sum-bsts/README.md new file mode 100644 index 000000000..790a334ba --- /dev/null +++ b/problems/two-sum-bsts/README.md @@ -0,0 +1,67 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/intersection-of-three-sorted-arrays "Intersection of Three Sorted Arrays") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/stepping-numbers "Stepping Numbers") + +## [5080. Two Sum BSTs (Medium)](https://leetcode.com/problems/two-sum-bsts "查找两棵二叉搜索树之和") + +

Given two binary search trees, return True if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target.

+ +

 

+ +

Example 1:

+ +

+ +
+Input: root1 = [2,1,4], root2 = [1,0,3], target = 5
+Output: true
+Explanation: 2 and 3 sum up to 5.
+
+ +
+

Example 2:

+ +

+ +
+Input: root1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18
+Output: false
+
+ +

 

+ +

Note:

+ +
    +
  1. Each tree has at most 5000 nodes.
  2. +
  3. -10^9 <= target, node.val <= 10^9
  4. +
+ +### Related Topics + [[Binary Search Tree](https://github.com/openset/leetcode/tree/master/tag/binary-search-tree/README.md)] + +### Similar Questions + 1. [Two Sum IV - Input is a BST](https://github.com/openset/leetcode/tree/master/problems/two-sum-iv-input-is-a-bst) (Easy) + +### Hints +
+Hint 1 +How can you reduce this problem to the classical Two Sum problem? +
+ +
+Hint 2 +Do an in-order traversal of each tree to convert them to sorted arrays. +
+ +
+Hint 3 +Solve the classical Two Sum problem. +
diff --git a/problems/two-sum-iv-input-is-a-bst/README.md b/problems/two-sum-iv-input-is-a-bst/README.md index 8ba39a3e1..081dd6153 100644 --- a/problems/two-sum-iv-input-is-a-bst/README.md +++ b/problems/two-sum-iv-input-is-a-bst/README.md @@ -54,3 +54,4 @@ Target = 28 1. [Two Sum](https://github.com/openset/leetcode/tree/master/problems/two-sum) (Easy) 1. [Two Sum II - Input array is sorted](https://github.com/openset/leetcode/tree/master/problems/two-sum-ii-input-array-is-sorted) (Easy) 1. [Two Sum III - Data structure design](https://github.com/openset/leetcode/tree/master/problems/two-sum-iii-data-structure-design) (Easy) + 1. [Two Sum BSTs](https://github.com/openset/leetcode/tree/master/problems/two-sum-bsts) (Medium) diff --git a/problems/valid-palindrome-iii/README.md b/problems/valid-palindrome-iii/README.md new file mode 100644 index 000000000..d92692a8d --- /dev/null +++ b/problems/valid-palindrome-iii/README.md @@ -0,0 +1,59 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/stepping-numbers "Stepping Numbers") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/play-with-chips "Play with Chips") + +## [5099. Valid Palindrome III (Hard)](https://leetcode.com/problems/valid-palindrome-iii "验证回文字符串 III") + +

Given a string s and an integer k, find out if the given string is a K-Palindrome or not.

+ +

A string is K-Palindrome if it can be transformed into a palindrome by removing at most k characters from it.

+ +

 

+

Example 1:

+ +
+Input: s = "abcdeca", k = 2
+Output: true
+Explanation: Remove 'b' and 'e' characters.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] + [[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +Can you reduce this problem to a classic problem? +
+ +
+Hint 2 +The problem is equivalent to finding any palindromic subsequence of length at least N-K where N is the length of the string. +
+ +
+Hint 3 +Try to find the longest palindromic subsequence. +
+ +
+Hint 4 +Use DP to do that. +
diff --git a/tag/README.md b/tag/README.md index 9af2cbbcc..e56d94bbc 100644 --- a/tag/README.md +++ b/tag/README.md @@ -26,6 +26,6 @@ | 29 | [Binary Indexed Tree](https://github.com/openset/leetcode/tree/master/tag/binary-indexed-tree/README.md) | [树状数组](https://openset.github.io/tags/binary-indexed-tree/) | | 30 | [Random](https://github.com/openset/leetcode/tree/master/tag/random/README.md) | [Random](https://openset.github.io/tags/random/) | | 31 | [Topological Sort](https://github.com/openset/leetcode/tree/master/tag/topological-sort/README.md) | [拓扑排序](https://openset.github.io/tags/topological-sort/) | | 32 | [Brainteaser](https://github.com/openset/leetcode/tree/master/tag/brainteaser/README.md) | [脑筋急转弯](https://openset.github.io/tags/brainteaser/) | | 33 | [Geometry](https://github.com/openset/leetcode/tree/master/tag/geometry/README.md) | [几何](https://openset.github.io/tags/geometry/) | | 34 | [Line Sweep](https://github.com/openset/leetcode/tree/master/tag/line-sweep/README.md) | [Line Sweep](https://openset.github.io/tags/line-sweep/) | -| 35 | [Rejection Sampling](https://github.com/openset/leetcode/tree/master/tag/rejection-sampling/README.md) | [Rejection Sampling](https://openset.github.io/tags/rejection-sampling/) | | 36 | [Reservoir Sampling](https://github.com/openset/leetcode/tree/master/tag/reservoir-sampling/README.md) | [蓄水池抽样](https://openset.github.io/tags/reservoir-sampling/) | -| 37 | [Binary Search Tree](https://github.com/openset/leetcode/tree/master/tag/binary-search-tree/README.md) | [二叉搜索树](https://openset.github.io/tags/binary-search-tree/) | | 38 | [Memoization](https://github.com/openset/leetcode/tree/master/tag/memoization/README.md) | [记忆化](https://openset.github.io/tags/memoization/) | +| 35 | [Binary Search Tree](https://github.com/openset/leetcode/tree/master/tag/binary-search-tree/README.md) | [二叉搜索树](https://openset.github.io/tags/binary-search-tree/) | | 36 | [Rejection Sampling](https://github.com/openset/leetcode/tree/master/tag/rejection-sampling/README.md) | [Rejection Sampling](https://openset.github.io/tags/rejection-sampling/) | +| 37 | [Reservoir Sampling](https://github.com/openset/leetcode/tree/master/tag/reservoir-sampling/README.md) | [蓄水池抽样](https://openset.github.io/tags/reservoir-sampling/) | | 38 | [Memoization](https://github.com/openset/leetcode/tree/master/tag/memoization/README.md) | [记忆化](https://openset.github.io/tags/memoization/) | | 39 | [Rolling Hash](https://github.com/openset/leetcode/tree/master/tag/rolling-hash/README.md) | [Rolling Hash](https://openset.github.io/tags/rolling-hash/) | | 40 | [Suffix Array](https://github.com/openset/leetcode/tree/master/tag/suffix-array/README.md) | [Suffix Array](https://openset.github.io/tags/suffix-array/) | diff --git a/tag/backtracking/README.md b/tag/backtracking/README.md index ff5e1ac68..f38689c12 100644 --- a/tag/backtracking/README.md +++ b/tag/backtracking/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 5081 | [步进数](https://github.com/openset/leetcode/tree/master/problems/stepping-numbers) | [[回溯算法](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] | Medium | | 1088 | [易混淆数 II](https://github.com/openset/leetcode/tree/master/problems/confusing-number-ii) 🔒 | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[回溯算法](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] | Hard | | 1087 | [字母切换](https://github.com/openset/leetcode/tree/master/problems/brace-expansion) 🔒 | [[回溯算法](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] | Medium | | 1079 | [活字印刷](https://github.com/openset/leetcode/tree/master/problems/letter-tile-possibilities) | [[回溯算法](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] | Medium | diff --git a/tag/binary-search-tree/README.md b/tag/binary-search-tree/README.md index b2d4b26c6..c436f8c02 100644 --- a/tag/binary-search-tree/README.md +++ b/tag/binary-search-tree/README.md @@ -9,4 +9,5 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 5080 | [查找两棵二叉搜索树之和](https://github.com/openset/leetcode/tree/master/problems/two-sum-bsts) | [[二叉搜索树](https://github.com/openset/leetcode/tree/master/tag/binary-search-tree/README.md)] | Medium | | 1038 | [从二叉搜索树到更大和树](https://github.com/openset/leetcode/tree/master/problems/binary-search-tree-to-greater-sum-tree) | [[二叉搜索树](https://github.com/openset/leetcode/tree/master/tag/binary-search-tree/README.md)] | Medium | diff --git a/tag/dynamic-programming/README.md b/tag/dynamic-programming/README.md index c16bb9675..8859a0d98 100644 --- a/tag/dynamic-programming/README.md +++ b/tag/dynamic-programming/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 5099 | [验证回文字符串 III](https://github.com/openset/leetcode/tree/master/problems/valid-palindrome-iii) | [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Hard | | 1147 | [段式回文](https://github.com/openset/leetcode/tree/master/problems/longest-chunked-palindrome-decomposition) | [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Hard | | 1136 | [平行课程](https://github.com/openset/leetcode/tree/master/problems/parallel-courses) 🔒 | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[图](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/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 | diff --git a/tag/hash-table/README.md b/tag/hash-table/README.md index 59fc6d3d7..064cdbd60 100644 --- a/tag/hash-table/README.md +++ b/tag/hash-table/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 5079 | [三个有序数组的交集](https://github.com/openset/leetcode/tree/master/problems/intersection-of-three-sorted-arrays) | [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Easy | | 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 | diff --git a/tag/string/README.md b/tag/string/README.md index 93e4a9bd7..913f6ee80 100644 --- a/tag/string/README.md +++ b/tag/string/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 5099 | [验证回文字符串 III](https://github.com/openset/leetcode/tree/master/problems/valid-palindrome-iii) | [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Hard | | 1181 | [前后拼接](https://github.com/openset/leetcode/tree/master/problems/before-and-after-puzzle) 🔒 | [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Medium | | 1180 | [统计只含单一字母的子串](https://github.com/openset/leetcode/tree/master/problems/count-substrings-with-only-one-distinct-letter) 🔒 | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/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 | diff --git a/tag/tags.json b/tag/tags.json index ab8436f0f..cc95069b6 100644 --- a/tag/tags.json +++ b/tag/tags.json @@ -169,6 +169,11 @@ "Slug": "line-sweep", "TranslatedName": "Line Sweep" }, + { + "Name": "Binary Search Tree", + "Slug": "binary-search-tree", + "TranslatedName": "二叉搜索树" + }, { "Name": "Rejection Sampling", "Slug": "rejection-sampling", @@ -179,11 +184,6 @@ "Slug": "reservoir-sampling", "TranslatedName": "蓄水池抽样" }, - { - "Name": "Binary Search Tree", - "Slug": "binary-search-tree", - "TranslatedName": "二叉搜索树" - }, { "Name": "Memoization", "Slug": "memoization", diff --git a/tag/two-pointers/README.md b/tag/two-pointers/README.md index 799973887..b42d4fbcf 100644 --- a/tag/two-pointers/README.md +++ b/tag/two-pointers/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 5079 | [三个有序数组的交集](https://github.com/openset/leetcode/tree/master/problems/intersection-of-three-sorted-arrays) | [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Easy | | 1093 | [大样本统计](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Medium | | 1004 | [最大连续1的个数 III](https://github.com/openset/leetcode/tree/master/problems/max-consecutive-ones-iii) | [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Medium | | 992 | [K 个不同整数的子数组](https://github.com/openset/leetcode/tree/master/problems/subarrays-with-k-different-integers) | [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Hard |