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

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
awesee merged 1 commit into master from develop
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
View file Open in desktop
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&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>

<p>Return the <em>decimal value</em> of the number in the linked list.</p>

<p>&nbsp;</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>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li>The Linked List is not empty.</li>
<li>Number of nodes&nbsp;will not exceed <code>30</code>.</li>
<li>Each node&#39;s value is either&nbsp;<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
View file Open in desktop
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&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>

<p>Return that integer.</p>

<p>&nbsp;</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>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= arr.length &lt;= 10^4</code></li>
<li><code>0 &lt;= arr[i] &lt;= 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>
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[< 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")

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

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

Expand Down Expand Up @@ -55,6 +55,3 @@ From 7 to 8 is contained in the table.
Number 9 is missing in the table.
Number 10 is contained in the table.
</pre>

### Similar Questions
1. [Report Contiguous Dates](https://github.com/openset/leetcode/tree/master/problems/report-contiguous-dates) (Hard)
2 changes: 1 addition & 1 deletion problems/flip-game-ii/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Derive your algorithm&#39;s runtime complexity.</p>

### Related Topics
[[Minimax](https://github.com/openset/leetcode/tree/master/tag/minimax/README.md)]
[[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)]
[[Minimax](https://github.com/openset/leetcode/tree/master/tag/minimax/README.md)]

### Similar Questions
1. [Nim Game](https://github.com/openset/leetcode/tree/master/problems/nim-game) (Easy)
Expand Down
59 changes: 59 additions & 0 deletions problems/iterator-for-combination/README.md
View file Open in desktop
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&nbsp;<code>characters</code>&nbsp;of <strong>sorted distinct</strong> lowercase English letters and a number&nbsp;<code>combinationLength</code> as arguments.</li>
<li>A function <em>next()</em>&nbsp;that returns the next combination of length <code>combinationLength</code>&nbsp;in <strong>lexicographical order</strong>.</li>
<li>A function <em>hasNext()</em> that returns <code>True</code>&nbsp;if and only if&nbsp;there exists a next combination.</li>
</ul>

<p>&nbsp;</p>

<p><b>Example:</b></p>

<pre>
CombinationIterator iterator = new CombinationIterator(&quot;abc&quot;, 2); // creates the iterator.

iterator.next(); // returns &quot;ab&quot;
iterator.hasNext(); // returns true
iterator.next(); // returns &quot;ac&quot;
iterator.hasNext(); // returns true
iterator.next(); // returns &quot;bc&quot;
iterator.hasNext(); // returns false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= combinationLength &lt;=&nbsp;characters.length &lt;= 15</code></li>
<li>There will be at most <code>10^4</code> function calls per test.</li>
<li>It&#39;s guaranteed that all&nbsp;calls&nbsp;of the function <code>next</code>&nbsp;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>
View file Open in desktop
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>&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>

<p>&nbsp;</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>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= m, n &lt;= 300</code></li>
<li><code>m == mat.length</code></li>
<li><code>n == mat[i].length</code></li>
<li><code>0 &lt;= mat[i][j] &lt;= 10000</code></li>
<li><code>0 &lt;= threshold&nbsp;&lt;= 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
View file Open in desktop
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&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>

<p>Return the&nbsp;minimum&nbsp;sum of a falling path with non-zero shifts.</p>

<p>&nbsp;</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&nbsp;[1,5,7], so the answer is&nbsp;13.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= arr.length == arr[i].length &lt;= 200</code></li>
<li><code>-99 &lt;= arr[i][j] &lt;= 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>
Loading

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