Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f0300b3

Browse files
author
Shuo
authored
Merge pull request #743 from openset/develop
Add: new
2 parents 6c0745f + a937658 commit f0300b3

File tree

22 files changed

+521
-20
lines changed

22 files changed

+521
-20
lines changed

‎README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1293">1293</span> | [Shortest Path in a Grid with Obstacles Elimination](https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination "网格中的最短路径") | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-path-in-a-grid-with-obstacles-elimination) | Hard |
66+
| <span id="1292">1292</span> | [Maximum Side Length of a Square with Sum Less than or Equal to Threshold](https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold "元素和小于等于阈值的正方形的最大边长") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold) | Medium |
67+
| <span id="1291">1291</span> | [Sequential Digits](https://leetcode.com/problems/sequential-digits "顺次数") | [Go](https://github.com/openset/leetcode/tree/master/problems/sequential-digits) | Medium |
68+
| <span id="1290">1290</span> | [Convert Binary Number in a Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer "二进制链表转整数") | [Go](https://github.com/openset/leetcode/tree/master/problems/convert-binary-number-in-a-linked-list-to-integer) | Easy |
69+
| <span id="1289">1289</span> | [Minimum Falling Path Sum II](https://leetcode.com/problems/minimum-falling-path-sum-ii "下降路径最小和 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-falling-path-sum-ii) | Hard |
70+
| <span id="1288">1288</span> | [Remove Covered Intervals](https://leetcode.com/problems/remove-covered-intervals "删除被覆盖区间") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-covered-intervals) | Medium |
71+
| <span id="1287">1287</span> | [Element Appearing More Than 25% In Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array "有序数组中出现次数超过25%的元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/element-appearing-more-than-25-in-sorted-array) | Easy |
72+
| <span id="1286">1286</span> | [Iterator for Combination](https://leetcode.com/problems/iterator-for-combination "字母组合迭代器") | [Go](https://github.com/openset/leetcode/tree/master/problems/iterator-for-combination) | Medium |
6573
| <span id="1285">1285</span> | [Find the Start and End Number of Continuous Ranges](https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/find-the-start-and-end-number-of-continuous-ranges) | Medium |
6674
| <span id="1284">1284</span> | [Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix "转化为全零矩阵的最少反转次数") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) | Hard |
6775
| <span id="1283">1283</span> | [Find the Smallest Divisor Given a Threshold](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold "使结果不超过阈值的最小除数") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-the-smallest-divisor-given-a-threshold) | Medium |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-falling-path-sum-ii "Minimum Falling Path Sum II")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/sequential-digits "Sequential Digits")
11+
12+
## [1290. Convert Binary Number in a Linked List to Integer (Easy)](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer "二进制链表转整数")
13+
14+
<p>Given <code>head</code> which is a reference node to&nbsp;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>
15+
16+
<p>Return the <em>decimal value</em> of the number in the linked list.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/05/graph-1.png" style="width: 426px; height: 108px;" />
21+
<pre>
22+
<strong>Input:</strong> head = [1,0,1]
23+
<strong>Output:</strong> 5
24+
<strong>Explanation:</strong> (101) in base 2 = (5) in base 10
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> head = [0]
31+
<strong>Output:</strong> 0
32+
</pre>
33+
34+
<p><strong>Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> head = [1]
38+
<strong>Output:</strong> 1
39+
</pre>
40+
41+
<p><strong>Example 4:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong> head = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]
45+
<strong>Output:</strong> 18880
46+
</pre>
47+
48+
<p><strong>Example 5:</strong></p>
49+
50+
<pre>
51+
<strong>Input:</strong> head = [0,0]
52+
<strong>Output:</strong> 0
53+
</pre>
54+
55+
<p>&nbsp;</p>
56+
<p><strong>Constraints:</strong></p>
57+
58+
<ul>
59+
<li>The Linked List is not empty.</li>
60+
<li>Number of nodes&nbsp;will not exceed <code>30</code>.</li>
61+
<li>Each node&#39;s value is either&nbsp;<code>0</code> or <code>1</code>.</li>
62+
</ul>
63+
64+
### Related Topics
65+
[[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)]
66+
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)]
67+
68+
### Hints
69+
<details>
70+
<summary>Hint 1</summary>
71+
Traverse the linked list and store all values in a string or array. convert the values obtained to decimal value.
72+
</details>
73+
74+
<details>
75+
<summary>Hint 2</summary>
76+
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.
77+
</details>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/iterator-for-combination "Iterator for Combination")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/remove-covered-intervals "Remove Covered Intervals")
11+
12+
## [1287. Element Appearing More Than 25% In Sorted Array (Easy)](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array "有序数组中出现次数超过25%的元素")
13+
14+
<p>Given an&nbsp;integer array&nbsp;<strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time.</p>
15+
16+
<p>Return that integer.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
<pre><strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10]
21+
<strong>Output:</strong> 6
22+
</pre>
23+
<p>&nbsp;</p>
24+
<p><strong>Constraints:</strong></p>
25+
26+
<ul>
27+
<li><code>1 &lt;= arr.length &lt;= 10^4</code></li>
28+
<li><code>0 &lt;= arr[i] &lt;= 10^5</code></li>
29+
</ul>
30+
31+
### Related Topics
32+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
33+
34+
### Hints
35+
<details>
36+
<summary>Hint 1</summary>
37+
Divide the array in four parts [1 - 25%] [25 - 50 %] [50 - 75 %] [75% - 100%]
38+
</details>
39+
40+
<details>
41+
<summary>Hint 2</summary>
42+
The answer should be in one of the ends of the intervals.
43+
</details>
44+
45+
<details>
46+
<summary>Hint 3</summary>
47+
In order to check which is element is the answer we can count the frequency with binarySearch.
48+
</details>

‎problems/find-the-start-and-end-number-of-continuous-ranges/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/iterator-for-combination"Iterator for Combination")
1111

1212
## [1285. Find the Start and End Number of Continuous Ranges (Medium)](https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges "")
1313

@@ -55,6 +55,3 @@ From 7 to 8 is contained in the table.
5555
Number 9 is missing in the table.
5656
Number 10 is contained in the table.
5757
</pre>
58-
59-
### Similar Questions
60-
1. [Report Contiguous Dates](https://github.com/openset/leetcode/tree/master/problems/report-contiguous-dates) (Hard)

‎problems/flip-game-ii/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
Derive your algorithm&#39;s runtime complexity.</p>
2828

2929
### Related Topics
30-
[[Minimax](https://github.com/openset/leetcode/tree/master/tag/minimax/README.md)]
3130
[[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)]
31+
[[Minimax](https://github.com/openset/leetcode/tree/master/tag/minimax/README.md)]
3232

3333
### Similar Questions
3434
1. [Nim Game](https://github.com/openset/leetcode/tree/master/problems/nim-game) (Easy)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< 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")
9+
10+
[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")
11+
12+
## [1286. Iterator for Combination (Medium)](https://leetcode.com/problems/iterator-for-combination "字母组合迭代器")
13+
14+
<p>Design an Iterator class, which has:</p>
15+
16+
<ul>
17+
<li>A constructor that takes a string&nbsp;<code>characters</code>&nbsp;of <strong>sorted distinct</strong> lowercase English letters and a number&nbsp;<code>combinationLength</code> as arguments.</li>
18+
<li>A function <em>next()</em>&nbsp;that returns the next combination of length <code>combinationLength</code>&nbsp;in <strong>lexicographical order</strong>.</li>
19+
<li>A function <em>hasNext()</em> that returns <code>True</code>&nbsp;if and only if&nbsp;there exists a next combination.</li>
20+
</ul>
21+
22+
<p>&nbsp;</p>
23+
24+
<p><b>Example:</b></p>
25+
26+
<pre>
27+
CombinationIterator iterator = new CombinationIterator(&quot;abc&quot;, 2); // creates the iterator.
28+
29+
iterator.next(); // returns &quot;ab&quot;
30+
iterator.hasNext(); // returns true
31+
iterator.next(); // returns &quot;ac&quot;
32+
iterator.hasNext(); // returns true
33+
iterator.next(); // returns &quot;bc&quot;
34+
iterator.hasNext(); // returns false
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>1 &lt;= combinationLength &lt;=&nbsp;characters.length &lt;= 15</code></li>
42+
<li>There will be at most <code>10^4</code> function calls per test.</li>
43+
<li>It&#39;s guaranteed that all&nbsp;calls&nbsp;of the function <code>next</code>&nbsp;are valid.</li>
44+
</ul>
45+
46+
### Related Topics
47+
[[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)]
48+
[[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)]
49+
50+
### Hints
51+
<details>
52+
<summary>Hint 1</summary>
53+
Generate all combinations as a preprocessing.
54+
</details>
55+
56+
<details>
57+
<summary>Hint 2</summary>
58+
Use bit masking to generate all the combinations.
59+
</details>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/sequential-digits "Sequential Digits")
9+
10+
[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")
11+
12+
## [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 "元素和小于等于阈值的正方形的最大边长")
13+
14+
<p>Given a <code>m x n</code>&nbsp;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>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/05/e1.png" style="width: 335px; height: 186px;" />
19+
<pre>
20+
<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
21+
<strong>Output:</strong> 2
22+
<strong>Explanation:</strong> The maximum side length of square with sum less than 4 is 2 as shown.
23+
</pre>
24+
25+
<p><strong>Example 2:</strong></p>
26+
27+
<pre>
28+
<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
29+
<strong>Output:</strong> 0
30+
</pre>
31+
32+
<p><strong>Example 3:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> mat = [[1,1,1,1],[1,0,0,0],[1,0,0,0],[1,0,0,0]], threshold = 6
36+
<strong>Output:</strong> 3
37+
</pre>
38+
39+
<p><strong>Example 4:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> mat = [[18,70],[61,1],[25,85],[14,40],[11,96],[97,96],[63,45]], threshold = 40184
43+
<strong>Output:</strong> 2
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
<p><strong>Constraints:</strong></p>
48+
49+
<ul>
50+
<li><code>1 &lt;= m, n &lt;= 300</code></li>
51+
<li><code>m == mat.length</code></li>
52+
<li><code>n == mat[i].length</code></li>
53+
<li><code>0 &lt;= mat[i][j] &lt;= 10000</code></li>
54+
<li><code>0 &lt;= threshold&nbsp;&lt;= 10^5</code></li>
55+
</ul>
56+
57+
### Related Topics
58+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
59+
[[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)]
60+
61+
### Hints
62+
<details>
63+
<summary>Hint 1</summary>
64+
Store prefix sum of all grids in another 2D array.
65+
</details>
66+
67+
<details>
68+
<summary>Hint 2</summary>
69+
Try all possible solutions and if you cannot find one return -1.
70+
</details>
71+
72+
<details>
73+
<summary>Hint 3</summary>
74+
If x is a valid answer then any y < x is also valid answer. Use binary search to find answer.
75+
</details>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/remove-covered-intervals "Remove Covered Intervals")
9+
10+
[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")
11+
12+
## [1289. Minimum Falling Path Sum II (Hard)](https://leetcode.com/problems/minimum-falling-path-sum-ii "下降路径最小和 II")
13+
14+
<p>Given a square grid&nbsp;of integers&nbsp;<code>arr</code>, a <em>falling path with non-zero shifts</em>&nbsp;is a choice of&nbsp;exactly one element from each row of <code>arr</code>, such that no two elements chosen in adjacent rows are in&nbsp;the same column.</p>
15+
16+
<p>Return the&nbsp;minimum&nbsp;sum of a falling path with non-zero shifts.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> arr = [[1,2,3],[4,5,6],[7,8,9]]
23+
<strong>Output:</strong> 13
24+
<strong>Explanation: </strong>
25+
The possible falling paths are:
26+
[1,5,9], [1,5,7], [1,6,7], [1,6,8],
27+
[2,4,8], [2,4,9], [2,6,7], [2,6,8],
28+
[3,4,8], [3,4,9], [3,5,7], [3,5,9]
29+
The falling path with the smallest sum is&nbsp;[1,5,7], so the answer is&nbsp;13.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= arr.length == arr[i].length &lt;= 200</code></li>
37+
<li><code>-99 &lt;= arr[i][j] &lt;= 99</code></li>
38+
</ul>
39+
40+
### Related Topics
41+
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
42+
43+
### Hints
44+
<details>
45+
<summary>Hint 1</summary>
46+
Use dynamic programming.
47+
</details>
48+
49+
<details>
50+
<summary>Hint 2</summary>
51+
Let dp[i][j] be the answer for the first i rows such that column j is chosen from row i.
52+
</details>
53+
54+
<details>
55+
<summary>Hint 3</summary>
56+
Use the concept of cumulative array to optimize the complexity of the solution.
57+
</details>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /