-
Notifications
You must be signed in to change notification settings - Fork 130
Add: new #728
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 #728
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
72 changes: 72 additions & 0 deletions
problems/count-square-submatrices-with-all-ones/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,72 @@ | ||
<!--|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/number-of-burgers-with-no-waste-of-ingredients "Number of Burgers with No Waste of Ingredients") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/palindrome-partitioning-iii "Palindrome Partitioning III") | ||
|
||
## [1277. Count Square Submatrices with All Ones (Medium)](https://leetcode.com/problems/count-square-submatrices-with-all-ones "统计全为 1 的正方形子矩阵") | ||
|
||
<p>Given a <code>m * n</code> matrix of ones and zeros, return how many <strong>square</strong> submatrices have all ones.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> matrix = | ||
[ | ||
[0,1,1,1], | ||
[1,1,1,1], | ||
[0,1,1,1] | ||
] | ||
<strong>Output:</strong> 15 | ||
<strong>Explanation:</strong> | ||
There are <strong>10</strong> squares of side 1. | ||
There are <strong>4</strong> squares of side 2. | ||
There is <strong>1</strong> square of side 3. | ||
Total number of squares = 10 + 4 + 1 = <strong>15</strong>. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> matrix = | ||
[ | ||
[1,0,1], | ||
[1,1,0], | ||
[1,1,0] | ||
] | ||
<strong>Output:</strong> 7 | ||
<strong>Explanation:</strong> | ||
There are <b>6</b> squares of side 1. | ||
There is <strong>1</strong> square of side 2. | ||
Total number of squares = 6 + 1 = <b>7</b>. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= arr.length <= 300</code></li> | ||
<li><code>1 <= arr[0].length <= 300</code></li> | ||
<li><code>0 <= arr[i][j] <= 1</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | ||
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Create an additive table that counts the sum of elements of submatrix with the superior corner at (0,0). | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Loop over all subsquares in O(n^3) and check if the sum make the whole array to be ones, if it checks then add 1 to the answer. | ||
</details> |
101 changes: 101 additions & 0 deletions
problems/find-winner-on-a-tic-tac-toe-game/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,101 @@ | ||
<!--|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/number-of-ships-in-a-rectangle "Number of Ships in a Rectangle") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-burgers-with-no-waste-of-ingredients "Number of Burgers with No Waste of Ingredients") | ||
|
||
## [1275. Find Winner on a Tic Tac Toe Game (Easy)](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game "找出井字棋的获胜者") | ||
|
||
<p>Tic-tac-toe is played by two players <em>A</em> and <em>B</em> on a <i>3</i> x <i>3</i> grid.</p> | ||
|
||
<p>Here are the rules of Tic-Tac-Toe:</p> | ||
|
||
<ul> | ||
<li>Players take turns placing characters into empty squares (" ").</li> | ||
<li>The first player <em>A</em> always places "X" characters, while the second player <em>B</em> always places "O" characters.</li> | ||
<li>"X" and "O" characters are always placed into empty squares, never on filled ones.</li> | ||
<li>The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.</li> | ||
<li>The game also ends if all squares are non-empty.</li> | ||
<li>No more moves can be played if the game is over.</li> | ||
</ul> | ||
|
||
<p>Given an array <code>moves</code> where each element is another array of size 2 corresponding to the row and column of the grid where they mark their respective character in the order in which <em>A</em> and <em>B</em> play.</p> | ||
|
||
<p>Return the winner of the game if it exists (<em>A</em> or <em>B</em>), in case the game ends in a draw return "Draw", if there are still movements to play return "Pending".</p> | ||
|
||
<p>You can assume that <code>moves</code> is <strong>valid</strong> (It follows the rules of Tic-Tac-Toe), the grid is initially empty and <em>A</em> will play <strong>first</strong>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> moves = [[0,0],[2,0],[1,1],[2,1],[2,2]] | ||
<strong>Output:</strong> "A" | ||
<strong>Explanation:</strong> "A" wins, he always plays first. | ||
"X " "X " "X " "X " "<strong>X</strong> " | ||
" " -> " " -> " X " -> " X " -> " <strong>X</strong> " | ||
" " "O " "O " "OO " "OO<strong>X</strong>" | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]] | ||
<strong>Output:</strong> "B" | ||
<strong>Explanation:</strong> "B" wins. | ||
"X " "X " "XX " "XXO" "XXO" "XX<strong>O</strong>" | ||
" " -> " O " -> " O " -> " O " -> "XO " -> "X<strong>O</strong> " | ||
" " " " " " " " " " "<strong>O</strong> " | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]] | ||
<strong>Output:</strong> "Draw" | ||
<strong>Explanation:</strong> The game ends in a draw since there are no moves to make. | ||
"XXO" | ||
"OOX" | ||
"XOX" | ||
</pre> | ||
|
||
<p><strong>Example 4:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> moves = [[0,0],[1,1]] | ||
<strong>Output:</strong> "Pending" | ||
<strong>Explanation:</strong> The game has not finished yet. | ||
"X " | ||
" O " | ||
" " | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= moves.length <= 9</code></li> | ||
<li><code>moves[i].length == 2</code></li> | ||
<li><code>0 <= moves[i][j] <= 2</code></li> | ||
<li>There are no repeated elements on <code>moves</code>.</li> | ||
<li><code>moves</code> follow the rules of tic tac toe.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
It's straightforward to check if A or B won or not, check for each row/column/diag if all the three are the same. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Then if no one wins, the game is a draw iff the board is full, i.e. moves.length = 9 otherwise is pending. | ||
</details> |
99 changes: 99 additions & 0 deletions
problems/number-of-burgers-with-no-waste-of-ingredients/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,99 @@ | ||
<!--|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-winner-on-a-tic-tac-toe-game "Find Winner on a Tic Tac Toe Game") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/count-square-submatrices-with-all-ones "Count Square Submatrices with All Ones") | ||
|
||
## [1276. Number of Burgers with No Waste of Ingredients (Medium)](https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients "不浪费原料的汉堡制作方案") | ||
|
||
<p>Given two integers <code>tomatoSlices</code> and <code>cheeseSlices</code>. The ingredients of different burgers are as follows:</p> | ||
|
||
<ul> | ||
<li><strong>Jumbo Burger:</strong> 4 tomato slices and 1 cheese slice.</li> | ||
<li><strong>Small Burger:</strong> 2 Tomato slices and 1 cheese slice.</li> | ||
</ul> | ||
|
||
<p>Return <code>[total_jumbo, total_small]</code> so that the number of remaining <code>tomatoSlices</code> equal to 0 and the number of remaining <code>cheeseSlices</code> equal to 0. If it is not possible to make the remaining <code>tomatoSlices</code> and <code>cheeseSlices</code> equal to 0 return <code>[]</code>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> tomatoSlices = 16, cheeseSlices = 7 | ||
<strong>Output:</strong> [1,6] | ||
<strong>Explantion:</strong> To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese. There will be no remaining ingredients. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> tomatoSlices = 17, cheeseSlices = 4 | ||
<strong>Output:</strong> [] | ||
<strong>Explantion:</strong> There will be no way to use all ingredients to make small and jumbo burgers. | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> tomatoSlices = 4, cheeseSlices = 17 | ||
<strong>Output:</strong> [] | ||
<strong>Explantion:</strong> Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining. | ||
</pre> | ||
|
||
<p><strong>Example 4:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> tomatoSlices = 0, cheeseSlices = 0 | ||
<strong>Output:</strong> [0,0] | ||
</pre> | ||
|
||
<p><strong>Example 5:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> tomatoSlices = 2, cheeseSlices = 1 | ||
<strong>Output:</strong> [0,1] | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>0 <= tomatoSlices <= 10^7</code></li> | ||
<li><code>0 <= cheeseSlices <= 10^7</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)] | ||
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Can we have an answer if the number of tomatoes is odd ? | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
If we have answer will be there multiple answers or just one answer ? | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
Let us define number of jumbo burgers as X and number of small burgers as Y | ||
We have to find an x and y in this equation | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 4</summary> | ||
1. 4X + 2Y = tomato | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 5</summary> | ||
2. X + Y = cheese | ||
</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
66 changes: 66 additions & 0 deletions
problems/palindrome-partitioning-iii/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,66 @@ | ||
<!--|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/count-square-submatrices-with-all-ones "Count Square Submatrices with All Ones") | ||
|
||
Next > | ||
|
||
## [1278. Palindrome Partitioning III (Hard)](https://leetcode.com/problems/palindrome-partitioning-iii "分割回文串 III") | ||
|
||
<p>You are given a string <code>s</code> containing lowercase letters and an integer <code>k</code>. You need to :</p> | ||
|
||
<ul> | ||
<li>First, change some characters of <code>s</code> to other lowercase English letters.</li> | ||
<li>Then divide <code>s</code> into <code>k</code> non-empty disjoint substrings such that each substring is palindrome.</li> | ||
</ul> | ||
|
||
<p>Return the minimal number of characters that you need to change to divide the string.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> s = "abc", k = 2 | ||
<strong>Output:</strong> 1 | ||
<strong>Explanation:</strong> You can split the string into "ab" and "c", and change 1 character in "ab" to make it palindrome. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> s = "aabbc", k = 3 | ||
<strong>Output:</strong> 0 | ||
<strong>Explanation:</strong> You can split the string into "aa", "bb" and "c", all of them are palindrome.</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> s = "leetcode", k = 8 | ||
<strong>Output:</strong> 0 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= k <= s.length <= 100</code>.</li> | ||
<li><code>s</code> only contains lowercase English letters.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
For each substring calculate the minimum number of steps to make it palindrome and store it in a table. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Create a dp(pos, cnt) which means the minimum number of characters changed for the suffix of s starting on pos splitting the suffix on cnt chunks. | ||
</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
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.