-
Notifications
You must be signed in to change notification settings - Fork 130
Add: new #743
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 #743
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
77 changes: 77 additions & 0 deletions
problems/convert-binary-number-in-a-linked-list-to-integer/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,77 @@ | ||
<!--|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](https://github.com/openset/leetcode/tree/master/problems/minimum-falling-path-sum-ii "Minimum Falling Path Sum II") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/sequential-digits "Sequential Digits") | ||
|
||
## [1290. Convert Binary Number in a Linked List to Integer (Easy)](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer "二进制链表转整数") | ||
|
||
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.</p> | ||
|
||
<p>Return the <em>decimal value</em> of the number in the linked list.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/05/graph-1.png" style="width: 426px; height: 108px;" /> | ||
<pre> | ||
<strong>Input:</strong> head = [1,0,1] | ||
<strong>Output:</strong> 5 | ||
<strong>Explanation:</strong> (101) in base 2 = (5) in base 10 | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> head = [0] | ||
<strong>Output:</strong> 0 | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> head = [1] | ||
<strong>Output:</strong> 1 | ||
</pre> | ||
|
||
<p><strong>Example 4:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> head = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0] | ||
<strong>Output:</strong> 18880 | ||
</pre> | ||
|
||
<p><strong>Example 5:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> head = [0,0] | ||
<strong>Output:</strong> 0 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li>The Linked List is not empty.</li> | ||
<li>Number of nodes will not exceed <code>30</code>.</li> | ||
<li>Each node's value is either <code>0</code> or <code>1</code>.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] | ||
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Traverse the linked list and store all values in a string or array. convert the values obtained to decimal value. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
You can solve the problem in O(1) memory using bits operation. use shift left operation ( << ) and or operation ( | ) to get the decimal value in one operation. | ||
</details> |
48 changes: 48 additions & 0 deletions
problems/element-appearing-more-than-25-in-sorted-array/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,48 @@ | ||
<!--|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](https://github.com/openset/leetcode/tree/master/problems/iterator-for-combination "Iterator for Combination") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/remove-covered-intervals "Remove Covered Intervals") | ||
|
||
## [1287. Element Appearing More Than 25% In Sorted Array (Easy)](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array "有序数组中出现次数超过25%的元素") | ||
|
||
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time.</p> | ||
|
||
<p>Return that integer.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
<pre><strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] | ||
<strong>Output:</strong> 6 | ||
</pre> | ||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= arr.length <= 10^4</code></li> | ||
<li><code>0 <= arr[i] <= 10^5</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Divide the array in four parts [1 - 25%] [25 - 50 %] [50 - 75 %] [75% - 100%] | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
The answer should be in one of the ends of the intervals. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
In order to check which is element is the answer we can count the frequency with binarySearch. | ||
</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
59 changes: 59 additions & 0 deletions
problems/iterator-for-combination/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](https://github.com/openset/leetcode/tree/master/problems/find-the-start-and-end-number-of-continuous-ranges "Find the Start and End Number of Continuous Ranges") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/element-appearing-more-than-25-in-sorted-array "Element Appearing More Than 25% In Sorted Array") | ||
|
||
## [1286. Iterator for Combination (Medium)](https://leetcode.com/problems/iterator-for-combination "字母组合迭代器") | ||
|
||
<p>Design an Iterator class, which has:</p> | ||
|
||
<ul> | ||
<li>A constructor that takes a string <code>characters</code> of <strong>sorted distinct</strong> lowercase English letters and a number <code>combinationLength</code> as arguments.</li> | ||
<li>A function <em>next()</em> that returns the next combination of length <code>combinationLength</code> in <strong>lexicographical order</strong>.</li> | ||
<li>A function <em>hasNext()</em> that returns <code>True</code> if and only if there exists a next combination.</li> | ||
</ul> | ||
|
||
<p> </p> | ||
|
||
<p><b>Example:</b></p> | ||
|
||
<pre> | ||
CombinationIterator iterator = new CombinationIterator("abc", 2); // creates the iterator. | ||
|
||
iterator.next(); // returns "ab" | ||
iterator.hasNext(); // returns true | ||
iterator.next(); // returns "ac" | ||
iterator.hasNext(); // returns true | ||
iterator.next(); // returns "bc" | ||
iterator.hasNext(); // returns false | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= combinationLength <= characters.length <= 15</code></li> | ||
<li>There will be at most <code>10^4</code> function calls per test.</li> | ||
<li>It's guaranteed that all calls of the function <code>next</code> are valid.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)] | ||
[[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Generate all combinations as a preprocessing. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Use bit masking to generate all the combinations. | ||
</details> |
75 changes: 75 additions & 0 deletions
...imum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold/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,75 @@ | ||
<!--|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](https://github.com/openset/leetcode/tree/master/problems/sequential-digits "Sequential Digits") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/shortest-path-in-a-grid-with-obstacles-elimination "Shortest Path in a Grid with Obstacles Elimination") | ||
|
||
## [1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold (Medium)](https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold "元素和小于等于阈值的正方形的最大边长") | ||
|
||
<p>Given a <code>m x n</code> matrix <code>mat</code> and an integer <code>threshold</code>. Return the maximum side-length of a square with a sum less than or equal to <code>threshold</code> or return <strong>0</strong> if there is no such square.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/05/e1.png" style="width: 335px; height: 186px;" /> | ||
<pre> | ||
<strong>Input:</strong> mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4 | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation:</strong> The maximum side length of square with sum less than 4 is 2 as shown. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> mat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1 | ||
<strong>Output:</strong> 0 | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> mat = [[1,1,1,1],[1,0,0,0],[1,0,0,0],[1,0,0,0]], threshold = 6 | ||
<strong>Output:</strong> 3 | ||
</pre> | ||
|
||
<p><strong>Example 4:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> mat = [[18,70],[61,1],[25,85],[14,40],[11,96],[97,96],[63,45]], threshold = 40184 | ||
<strong>Output:</strong> 2 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= m, n <= 300</code></li> | ||
<li><code>m == mat.length</code></li> | ||
<li><code>n == mat[i].length</code></li> | ||
<li><code>0 <= mat[i][j] <= 10000</code></li> | ||
<li><code>0 <= threshold <= 10^5</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | ||
[[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Store prefix sum of all grids in another 2D array. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Try all possible solutions and if you cannot find one return -1. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
If x is a valid answer then any y < x is also valid answer. Use binary search to find answer. | ||
</details> |
57 changes: 57 additions & 0 deletions
problems/minimum-falling-path-sum-ii/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,57 @@ | ||
<!--|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](https://github.com/openset/leetcode/tree/master/problems/remove-covered-intervals "Remove Covered Intervals") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/convert-binary-number-in-a-linked-list-to-integer "Convert Binary Number in a Linked List to Integer") | ||
|
||
## [1289. Minimum Falling Path Sum II (Hard)](https://leetcode.com/problems/minimum-falling-path-sum-ii "下降路径最小和 II") | ||
|
||
<p>Given a square grid of integers <code>arr</code>, a <em>falling path with non-zero shifts</em> is a choice of exactly one element from each row of <code>arr</code>, such that no two elements chosen in adjacent rows are in the same column.</p> | ||
|
||
<p>Return the minimum sum of a falling path with non-zero shifts.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> arr = [[1,2,3],[4,5,6],[7,8,9]] | ||
<strong>Output:</strong> 13 | ||
<strong>Explanation: </strong> | ||
The possible falling paths are: | ||
[1,5,9], [1,5,7], [1,6,7], [1,6,8], | ||
[2,4,8], [2,4,9], [2,6,7], [2,6,8], | ||
[3,4,8], [3,4,9], [3,5,7], [3,5,9] | ||
The falling path with the smallest sum is [1,5,7], so the answer is 13. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= arr.length == arr[i].length <= 200</code></li> | ||
<li><code>-99 <= arr[i][j] <= 99</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Use dynamic programming. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Let dp[i][j] be the answer for the first i rows such that column j is chosen from row i. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
Use the concept of cumulative array to optimize the complexity of the solution. | ||
</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.