From 3b37d75984bc1443e592e751e17f9be5dd9aeec5 Mon Sep 17 00:00:00 2001
From: openset Return a deep copy of the list. The Linked List is represented in the input/output as a list of Example 1: Example 2: Example 3: Example 4: Note: Constraints: Given an array of integers Example 1: Example 2: Example 3: Example 4: Constraints: Example 1: Example 2: Constraints:(0,0)
, (0,
of 2+2+2=6 is minimal. So return 6.
### Related Topics
- [[Sort](../../tag/sort/README.md)]
[[Math](../../tag/math/README.md)]
+ [[Sort](../../tag/sort/README.md)]
### Similar Questions
1. [Shortest Distance from All Buildings](../shortest-distance-from-all-buildings) (Hard)
diff --git a/problems/copy-list-with-random-pointer/README.md b/problems/copy-list-with-random-pointer/README.md
index ba40520ee..d09f36026 100644
--- a/problems/copy-list-with-random-pointer/README.md
+++ b/problems/copy-list-with-random-pointer/README.md
@@ -15,28 +15,53 @@
n
nodes. Each node is represented as a pair of [val, random_index]
where:
+
+
val
: an integer representing Node.val
random_index
: the index of the node (range from 0
to n-1
) where random pointer points to, or null
if it does not point to any node.
+Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
+Output: [[7,null],[13,0],[11,4],[10,2],[1,0]]
+
+
+
+Input: head = [[1,1],[2,1]]
+Output: [[1,1],[2,1]]
+
+
+
-Input:
-{"$id":"1","next":{"$id":"2","next":null,"random":{"$ref":"2"},"val":2},"random":{"$ref":"2"},"val":1}
-
-Explanation:
-Node 1's value is 1, both of its next and random pointer points to Node 2.
-Node 2's value is 2, its next pointer points to null and its random pointer points to itself.
+Input: head = [[3,null],[3,0],[3,null]]
+Output: [[3,null],[3,0],[3,null]]
-
+
+Input: head = []
+Output: []
+Explanation: Given linked list is empty (null pointer), so return null.
+
+
+
+
-
+
+
### Related Topics
[[Hash Table](../../tag/hash-table/README.md)]
diff --git a/problems/divide-array-in-sets-of-k-consecutive-numbers/README.md b/problems/divide-array-in-sets-of-k-consecutive-numbers/README.md
new file mode 100644
index 000000000..a0d5c312b
--- /dev/null
+++ b/problems/divide-array-in-sets-of-k-consecutive-numbers/README.md
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+[< Previous](../find-numbers-with-even-number-of-digits "Find Numbers with Even Number of Digits") + +[Next>](../maximum-number-of-occurrences-of-a-substring "Maximum Number of Occurrences of a Substring")
+
+## [1296. Divide Array in Sets of K Consecutive Numbers (Medium)](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers "划分数组为连续数字的集合")
+
+-10000 <= Node.val <= 10000
Node.random
is null or pointing to a node in the linked list.nums
and a positive integer k
, find whether it's possible to divide this array into sets of k
consecutive numbers
+Return True
if its possibleotherwise return False
.
+Input: nums = [1,2,3,3,4,4,5,6], k = 4
+Output: true
+Explanation: Array can be divided into [1,2,3,4] and [3,4,5,6].
+
+
+
+Input: nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3
+Output: true
+Explanation: Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].
+
+
+
+Input: nums = [3,3,2,2,1,1], k = 3
+Output: true
+
+
+
+Input: nums = [1,2,3,4], k = 3
+Output: false
+Explanation: Each array should be divided in subarrays of size 3.
+
+
+
+
+
+
+### Related Topics
+ [[Greedy](../../tag/greedy/README.md)]
+ [[Array](../../tag/array/README.md)]
+
+### Hints
+1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
1 <= k <= nums.length
Hint 1
+If the smallest number in the possible-to-split array is V, then numbers V+1, V+2, ... V+k-1 must contain there as well.
+Hint 2
+You can iteratively find k sets and remove them from array until it becomes empty.
+Hint 3
+Failure to do so would mean that array is unsplittable.
+nums
of integers, return how many of them contain an even number of digits.
+
+
+Input: nums = [12,345,2,6,7896]
+Output: 2
+Explanation:
+12 contains 2 digits (even number of digits).
+345 contains 3 digits (odd number of digits).
+2 contains 1 digit (odd number of digits).
+6 contains 1 digit (odd number of digits).
+7896 contains 4 digits (even number of digits).
+Therefore only 12 and 7896 contain an even number of digits.
+
+
+
+Input: nums = [555,901,482,1771]
+Output: 1
+Explanation:
+Only 1771 contains an even number of digits.
+
+
+
+
+
+
+### Related Topics
+ [[Array](../../tag/array/README.md)]
+
+### Hints
+1 <= nums.length <= 500
1 <= nums[i] <= 10^5
Hint 1
+How to compute the number of digits of a number ?
+Hint 2
+Divide the number by 10 again and again to get the number of digits.
+
Table: Delivery
Given n
boxes, each box is given in the format [status, candies, keys, containedBoxes]
where:
status[i]
: an integer which is 1 if box[i]
is open and 0 if box[i]
is closed.candies[i]
: an integer representing the number of candies in box[i]
.keys[i]
: an array contains the indices of the boxes you can open with the key in box[i]
.containedBoxes[i]
: an array contains the indices of the boxes found in box[i]
.You will start with some boxes given in initialBoxes
array. You can take all the candies in any open box and you can use the keys in it to open new boxes and you also can use the boxes you find in it.
Return the maximum number of candies you can get following the rules above.
+ + +Example 1:
+ ++Input: status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0] +Output: 16 +Explanation: You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2. Box 1 is closed and you don't have a key for it so you will open box 2. You will find 4 candies and a key to box 1 in box 2. +In box 1, you will find 5 candies and box 3 but you will not find a key to box 3 so box 3 will remain closed. +Total number of candies collected = 7 + 4 + 5 = 16 candy. ++ +
Example 2:
+ ++Input: status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0] +Output: 6 +Explanation: You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys. The total number of candies will be 6. ++ +
Example 3:
+ ++Input: status = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1] +Output: 1 ++ +
Example 4:
+ ++Input: status = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = [] +Output: 0 ++ +
Example 5:
+ ++Input: status = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0] +Output: 7 ++ + +
Constraints:
+ +1 <= status.length <= 1000
status.length == candies.length == keys.length == containedBoxes.length == n
status[i]
is 0
or 1
.1 <= candies[i] <= 1000
0 <= keys[i].length <= status.length
0 <= keys[i][j] < status.length
keys[i]
are unique.0 <= containedBoxes[i].length <= status.length
0 <= containedBoxes[i][j] < status.length
containedBoxes[i]
are unique.0 <= initialBoxes.length <= status.length
0 <= initialBoxes[i] < status.length
Given a string s
, return the maximum number of ocurrences of any substring under the following rules:
maxLetters
.minSize
and maxSize
inclusive.Example 1:
+ ++Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 +Output: 2 +Explanation: Substring "aab" has 2 ocurrences in the original string. +It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). ++ +
Example 2:
+ ++Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 +Output: 2 +Explanation: Substring "aaa" occur 2 times in the string. It can overlap. ++ +
Example 3:
+ ++Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 +Output: 3 ++ +
Example 4:
+ ++Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 +Output: 0 ++ + +
Constraints:
+ +1 <= s.length <= 10^5
1 <= maxLetters <= 26
1 <= minSize <= maxSize <= min(26, s.length)
s
only contains lowercase English letters.Table: Students
diff --git a/problems/weather-type-in-each-country/README.md b/problems/weather-type-in-each-country/README.md new file mode 100644 index 000000000..4f3e18a09 --- /dev/null +++ b/problems/weather-type-in-each-country/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](../shortest-path-in-a-grid-with-obstacles-elimination "Shortest Path in a Grid with Obstacles Elimination") + +[Next>](../find-numbers-with-even-number-of-digits "Find Numbers with Even Number of Digits") + +## [1294. Weather Type in Each Country (Easy)](https://leetcode.com/problems/weather-type-in-each-country "") + + diff --git a/problems/weather-type-in-each-country/mysql_schemas.sql b/problems/weather-type-in-each-country/mysql_schemas.sql new file mode 100644 index 000000000..047159d79 --- /dev/null +++ b/problems/weather-type-in-each-country/mysql_schemas.sql @@ -0,0 +1,27 @@ +Create table If Not Exists Countries (country_id int, country_name varchar(20)); +Create table If Not Exists Weather (country_id int, weather_state int, day date); +Truncate table Countries; +insert into Countries (country_id, country_name) values ('2', 'USA'); +insert into Countries (country_id, country_name) values ('3', 'Australia'); +insert into Countries (country_id, country_name) values ('7', 'Peru'); +insert into Countries (country_id, country_name) values ('5', 'China'); +insert into Countries (country_id, country_name) values ('8', 'Morocco'); +insert into Countries (country_id, country_name) values ('9', 'Spain'); +Truncate table Weather; +insert into Weather (country_id, weather_state, day) values ('2', '15', '2019-11-01'); +insert into Weather (country_id, weather_state, day) values ('2', '12', '2019-10-28'); +insert into Weather (country_id, weather_state, day) values ('2', '12', '2019-10-27'); +insert into Weather (country_id, weather_state, day) values ('3', '-2', '2019-11-10'); +insert into Weather (country_id, weather_state, day) values ('3', '0', '2019-11-11'); +insert into Weather (country_id, weather_state, day) values ('3', '3', '2019-11-12'); +insert into Weather (country_id, weather_state, day) values ('5', '16', '2019-11-07'); +insert into Weather (country_id, weather_state, day) values ('5', '18', '2019-11-09'); +insert into Weather (country_id, weather_state, day) values ('5', '21', '2019-11-23'); +insert into Weather (country_id, weather_state, day) values ('7', '25', '2019-11-28'); +insert into Weather (country_id, weather_state, day) values ('7', '22', '2019-12-01'); +insert into Weather (country_id, weather_state, day) values ('7', '20', '2019-12-02'); +insert into Weather (country_id, weather_state, day) values ('8', '25', '2019-11-05'); +insert into Weather (country_id, weather_state, day) values ('8', '27', '2019-11-15'); +insert into Weather (country_id, weather_state, day) values ('8', '31', '2019-11-25'); +insert into Weather (country_id, weather_state, day) values ('9', '7', '2019-10-23'); +insert into Weather (country_id, weather_state, day) values ('9', '3', '2019-12-23'); diff --git a/tag/array/README.md b/tag/array/README.md index 65b453837..c27081e6a 100644 --- a/tag/array/README.md +++ b/tag/array/README.md @@ -9,6 +9,8 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 1296 | [划分数组为连续数字的集合](../../problems/divide-array-in-sets-of-k-consecutive-numbers) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Medium | +| 1295 | [统计位数为偶数的数字](../../problems/find-numbers-with-even-number-of-digits) | [[数组](../array/README.md)] | Easy | | 1292 | [元素和小于等于阈值的正方形的最大边长](../../problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1287 | [有序数组中出现次数超过25%的元素](../../problems/element-appearing-more-than-25-in-sorted-array) | [[数组](../array/README.md)] | Easy | | 1277 | [统计全为 1 的正方形子矩阵](../../problems/count-square-submatrices-with-all-ones) | [[数组](../array/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | diff --git a/tag/bit-manipulation/README.md b/tag/bit-manipulation/README.md index b33bb8c94..c7a0a6025 100644 --- a/tag/bit-manipulation/README.md +++ b/tag/bit-manipulation/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 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 | | 1256 | [加密数字](../../problems/encode-number) 🔒 | [[位运算](../bit-manipulation/README.md)] [[数学](../math/README.md)] | Medium | | 1255 | [得分最高的单词集合](../../problems/maximum-score-words-formed-by-letters) | [[位运算](../bit-manipulation/README.md)] | Hard | diff --git a/tag/breadth-first-search/README.md b/tag/breadth-first-search/README.md index cc761a19f..e59be563c 100644 --- a/tag/breadth-first-search/README.md +++ b/tag/breadth-first-search/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 1298 | [你能从盒子里获得的最大糖果数](../../problems/maximum-candies-you-can-get-from-boxes) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 1293 | [网格中的最短路径](../../problems/shortest-path-in-a-grid-with-obstacles-elimination) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 1284 | [转化为全零矩阵的最少反转次数](../../problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 1263 | [推箱子](../../problems/minimum-moves-to-move-a-box-to-their-target-location) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | diff --git a/tag/greedy/README.md b/tag/greedy/README.md index 7c819aa53..f5e2fd318 100644 --- a/tag/greedy/README.md +++ b/tag/greedy/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 1296 | [划分数组为连续数字的集合](../../problems/divide-array-in-sets-of-k-consecutive-numbers) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Medium | | 1282 | [用户分组](../../problems/group-the-people-given-the-group-size-they-belong-to) | [[贪心算法](../greedy/README.md)] | Medium | | 1276 | [不浪费原料的汉堡制作方案](../../problems/number-of-burgers-with-no-waste-of-ingredients) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Medium | | 1253 | [重构 2 行二进制矩阵](../../problems/reconstruct-a-2-row-binary-matrix) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Medium | diff --git a/tag/string/README.md b/tag/string/README.md index 82fa26b3c..db4c81d85 100644 --- a/tag/string/README.md +++ b/tag/string/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 1297 | [子串的最大出现次数](../../problems/maximum-number-of-occurrences-of-a-substring) | [[位运算](../bit-manipulation/README.md)] [[字符串](../string/README.md)] | Medium | | 1271 | [十六进制魔术数字](../../problems/hexspeak) 🔒 | [[数学](../math/README.md)] [[字符串](../string/README.md)] | Easy | | 1268 | [搜索推荐系统](../../problems/search-suggestions-system) | [[字符串](../string/README.md)] | Medium | | 1249 | [移除无效的括号](../../problems/minimum-remove-to-make-valid-parentheses) | [[栈](../stack/README.md)] [[字符串](../string/README.md)] | Medium |