-
Notifications
You must be signed in to change notification settings - Fork 130
Add: new #749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Add: new #749
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
problems/divide-array-in-sets-of-k-consecutive-numbers/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< 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 "划分数组为连续数字的集合") | ||
|
||
<p>Given an array of integers <code>nums</code> and a positive integer <code>k</code>, find whether it's possible to divide this array into sets of <code>k</code> consecutive numbers<br /> | ||
Return <code>True</code> if its possible<strong> </strong>otherwise return <code>False</code>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [1,2,3,3,4,4,5,6], k = 4 | ||
<strong>Output:</strong> true | ||
<strong>Explanation:</strong> Array can be divided into [1,2,3,4] and [3,4,5,6]. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3 | ||
<strong>Output:</strong> true | ||
<strong>Explanation:</strong> Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11]. | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [3,3,2,2,1,1], k = 3 | ||
<strong>Output:</strong> true | ||
</pre> | ||
|
||
<p><strong>Example 4:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [1,2,3,4], k = 3 | ||
<strong>Output:</strong> false | ||
<strong>Explanation:</strong> Each array should be divided in subarrays of size 3. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 10^5</code></li> | ||
<li><code>1 <= nums[i] <= 10^9</code></li> | ||
<li><code>1 <= k <= nums.length</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Greedy](../../tag/greedy/README.md)] | ||
[[Array](../../tag/array/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
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. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
You can iteratively find k sets and remove them from array until it becomes empty. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
Failure to do so would mean that array is unsplittable. | ||
</details> |
59 changes: 59 additions & 0 deletions
problems/find-numbers-with-even-number-of-digits/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../weather-type-in-each-country "Weather Type in Each Country") | ||
|
||
[Next >](../divide-array-in-sets-of-k-consecutive-numbers "Divide Array in Sets of K Consecutive Numbers") | ||
|
||
## [1295. Find Numbers with Even Number of Digits (Easy)](https://leetcode.com/problems/find-numbers-with-even-number-of-digits "统计位数为偶数的数字") | ||
|
||
Given an array <code>nums</code> of integers, return how many of them contain an <strong>even number</strong> of digits. | ||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [12,345,2,6,7896] | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation: | ||
</strong>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. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [555,901,482,1771] | ||
<strong>Output:</strong> 1 | ||
<strong>Explanation: </strong> | ||
Only 1771 contains an even number of digits. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 500</code></li> | ||
<li><code>1 <= nums[i] <= 10^5</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Array](../../tag/array/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
How to compute the number of digits of a number ? | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Divide the number by 10 again and again to get the number of digits. | ||
</details> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
problems/maximum-candies-you-can-get-from-boxes/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../maximum-number-of-occurrences-of-a-substring "Maximum Number of Occurrences of a Substring") | ||
|
||
Next > | ||
|
||
## [1298. Maximum Candies You Can Get from Boxes (Hard)](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes "你能从盒子里获得的最大糖果数") | ||
|
||
<p>Given <code>n</code> boxes, each box is given in the format <code>[status, candies, keys, containedBoxes]</code> where:</p> | ||
|
||
<ul> | ||
<li><code>status[i]</code>: an integer which is <strong>1</strong> if <code>box[i]</code> is open and <strong>0</strong> if <code>box[i]</code> is closed.</li> | ||
<li><code>candies[i]</code>: an integer representing the number of candies in <code>box[i]</code>.</li> | ||
<li><code>keys[i]</code>: an array contains the indices of the boxes you can open with the key in <code>box[i]</code>.</li> | ||
<li><code>containedBoxes[i]</code>: an array contains the indices of the boxes found in <code>box[i]</code>.</li> | ||
</ul> | ||
|
||
<p>You will start with some boxes given in <code>initialBoxes</code> 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.</p> | ||
|
||
<p>Return <em>the maximum number of candies</em> you can get following the rules above.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0] | ||
<strong>Output:</strong> 16 | ||
<strong>Explanation:</strong> 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. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> 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] | ||
<strong>Output:</strong> 6 | ||
<strong>Explanation:</strong> 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. | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> status = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1] | ||
<strong>Output:</strong> 1 | ||
</pre> | ||
|
||
<p><strong>Example 4:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> status = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = [] | ||
<strong>Output:</strong> 0 | ||
</pre> | ||
|
||
<p><strong>Example 5:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> status = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0] | ||
<strong>Output:</strong> 7 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= status.length <= 1000</code></li> | ||
<li><code>status.length == candies.length == keys.length == containedBoxes.length == n</code></li> | ||
<li><code>status[i]</code> is <code>0</code> or <code>1</code>.</li> | ||
<li><code>1 <= candies[i] <= 1000</code></li> | ||
<li><code><font face="monospace">0 <= keys[i].length <= status.length</font></code></li> | ||
<li><code>0 <= keys[i][j] < status.length</code></li> | ||
<li>All values in <code>keys[i]</code> are unique.</li> | ||
<li><code><font face="monospace">0 <= </font>containedBoxes<font face="monospace">[i].length <= status.length</font></code></li> | ||
<li><code>0 <= containedBoxes[i][j] < status.length</code></li> | ||
<li>All values in <code>containedBoxes[i]</code> are unique.</li> | ||
<li>Each box is contained in one box at most.</li> | ||
<li><code>0 <= initialBoxes.length <= status.length</code></li> | ||
<li><code><font face="monospace">0 <= initialBoxes[i] < status.length</font></code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Breadth-first Search](../../tag/breadth-first-search/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Use Breadth First Search (BFS) to traverse all possible boxes you can open. Only push to the queue the boxes the you have with their keys. | ||
</details> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.