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 b9621a2

Browse files
author
Shuo
authored
Merge pull request #728 from openset/develop
Add: new
2 parents a087f61 + e56da2a commit b9621a2

File tree

14 files changed

+356
-1
lines changed

14 files changed

+356
-1
lines changed

‎README.md

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

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1278">1278</span> | [Palindrome Partitioning III](https://leetcode.com/problems/palindrome-partitioning-iii "分割回文串 III") | [Go](https://github.com/openset/leetcode/tree/master/problems/palindrome-partitioning-iii) | Hard |
66+
| <span id="1277">1277</span> | [Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones "统计全为 1 的正方形子矩阵") | [Go](https://github.com/openset/leetcode/tree/master/problems/count-square-submatrices-with-all-ones) | Medium |
67+
| <span id="1276">1276</span> | [Number of Burgers with No Waste of Ingredients](https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients "不浪费原料的汉堡制作方案") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-burgers-with-no-waste-of-ingredients) | Medium |
68+
| <span id="1275">1275</span> | [Find Winner on a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game "找出井字棋的获胜者") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-winner-on-a-tic-tac-toe-game) | Easy |
6569
| <span id="1274">1274</span> | [Number of Ships in a Rectangle](https://leetcode.com/problems/number-of-ships-in-a-rectangle "矩形内船只的数目") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-ships-in-a-rectangle) | Hard |
6670
| <span id="1273">1273</span> | [Delete Tree Nodes](https://leetcode.com/problems/delete-tree-nodes "删除树节点") | [Go](https://github.com/openset/leetcode/tree/master/problems/delete-tree-nodes) | Medium |
6771
| <span id="1272">1272</span> | [Remove Interval](https://leetcode.com/problems/remove-interval "删除区间") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-interval) | Medium |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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/number-of-burgers-with-no-waste-of-ingredients "Number of Burgers with No Waste of Ingredients")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/palindrome-partitioning-iii "Palindrome Partitioning III")
11+
12+
## [1277. Count Square Submatrices with All Ones (Medium)](https://leetcode.com/problems/count-square-submatrices-with-all-ones "统计全为 1 的正方形子矩阵")
13+
14+
<p>Given a <code>m * n</code> matrix of ones and zeros, return how many <strong>square</strong> submatrices have all ones.</p>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> matrix =
21+
[
22+
&nbsp; [0,1,1,1],
23+
&nbsp; [1,1,1,1],
24+
&nbsp; [0,1,1,1]
25+
]
26+
<strong>Output:</strong> 15
27+
<strong>Explanation:</strong>
28+
There are <strong>10</strong> squares of side 1.
29+
There are <strong>4</strong> squares of side 2.
30+
There is <strong>1</strong> square of side 3.
31+
Total number of squares = 10 + 4 + 1 = <strong>15</strong>.
32+
</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> matrix =
38+
[
39+
[1,0,1],
40+
[1,1,0],
41+
[1,1,0]
42+
]
43+
<strong>Output:</strong> 7
44+
<strong>Explanation:</strong>
45+
There are <b>6</b> squares of side 1.
46+
There is <strong>1</strong> square of side 2.
47+
Total number of squares = 6 + 1 = <b>7</b>.
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= arr.length&nbsp;&lt;= 300</code></li>
55+
<li><code>1 &lt;= arr[0].length&nbsp;&lt;= 300</code></li>
56+
<li><code>0 &lt;= arr[i][j] &lt;= 1</code></li>
57+
</ul>
58+
59+
### Related Topics
60+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
61+
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
62+
63+
### Hints
64+
<details>
65+
<summary>Hint 1</summary>
66+
Create an additive table that counts the sum of elements of submatrix with the superior corner at (0,0).
67+
</details>
68+
69+
<details>
70+
<summary>Hint 2</summary>
71+
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.
72+
</details>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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/number-of-ships-in-a-rectangle "Number of Ships in a Rectangle")
9+
10+
[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")
11+
12+
## [1275. Find Winner on a Tic Tac Toe Game (Easy)](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game "找出井字棋的获胜者")
13+
14+
<p>Tic-tac-toe is played&nbsp;by&nbsp;two players <em>A</em> and <em>B</em> on a&nbsp;<i>3</i>&nbsp;x&nbsp;<i>3</i>&nbsp;grid.</p>
15+
16+
<p>Here are the rules of Tic-Tac-Toe:</p>
17+
18+
<ul>
19+
<li>Players take turns placing characters into empty squares (&quot; &quot;).</li>
20+
<li>The first player <em>A</em> always places &quot;X&quot; characters, while the second player <em>B</em>&nbsp;always places &quot;O&quot; characters.</li>
21+
<li>&quot;X&quot; and &quot;O&quot; characters are always placed into empty squares, never on filled ones.</li>
22+
<li>The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.</li>
23+
<li>The game also ends if all squares are non-empty.</li>
24+
<li>No more moves can be played if the game is over.</li>
25+
</ul>
26+
27+
<p>Given an array <code>moves</code> where each element&nbsp;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>
28+
29+
<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 &quot;Draw&quot;, if there are still movements to play return &quot;Pending&quot;.</p>
30+
31+
<p>You can assume that&nbsp;<code>moves</code> is&nbsp;<strong>valid</strong> (It follows the rules of Tic-Tac-Toe),&nbsp;the grid is initially empty and <em>A</em> will play <strong>first</strong>.</p>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Example 1:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]
38+
<strong>Output:</strong> &quot;A&quot;
39+
<strong>Explanation:</strong> &quot;A&quot; wins, he always plays first.
40+
&quot;X &quot; &quot;X &quot; &quot;X &quot; &quot;X &quot; &quot;<strong>X</strong> &quot;
41+
&quot; &quot; -&gt; &quot; &quot; -&gt; &quot; X &quot; -&gt; &quot; X &quot; -&gt; &quot; <strong>X</strong> &quot;
42+
&quot; &quot; &quot;O &quot; &quot;O &quot; &quot;OO &quot; &quot;OO<strong>X</strong>&quot;
43+
</pre>
44+
45+
<p><strong>Example 2:</strong></p>
46+
47+
<pre>
48+
<strong>Input:</strong> moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]
49+
<strong>Output:</strong> &quot;B&quot;
50+
<strong>Explanation:</strong> &quot;B&quot; wins.
51+
&quot;X &quot; &quot;X &quot; &quot;XX &quot; &quot;XXO&quot; &quot;XXO&quot; &quot;XX<strong>O</strong>&quot;
52+
&quot; &quot; -&gt; &quot; O &quot; -&gt; &quot; O &quot; -&gt; &quot; O &quot; -&gt; &quot;XO &quot; -&gt; &quot;X<strong>O</strong> &quot;
53+
&quot; &quot; &quot; &quot; &quot; &quot; &quot; &quot; &quot; &quot; &quot;<strong>O</strong> &quot;
54+
</pre>
55+
56+
<p><strong>Example 3:</strong></p>
57+
58+
<pre>
59+
<strong>Input:</strong> moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]
60+
<strong>Output:</strong> &quot;Draw&quot;
61+
<strong>Explanation:</strong> The game ends in a draw since there are no moves to make.
62+
&quot;XXO&quot;
63+
&quot;OOX&quot;
64+
&quot;XOX&quot;
65+
</pre>
66+
67+
<p><strong>Example 4:</strong></p>
68+
69+
<pre>
70+
<strong>Input:</strong> moves = [[0,0],[1,1]]
71+
<strong>Output:</strong> &quot;Pending&quot;
72+
<strong>Explanation:</strong> The game has not finished yet.
73+
&quot;X &quot;
74+
&quot; O &quot;
75+
&quot; &quot;
76+
</pre>
77+
78+
<p>&nbsp;</p>
79+
<p><strong>Constraints:</strong></p>
80+
81+
<ul>
82+
<li><code>1 &lt;= moves.length &lt;= 9</code></li>
83+
<li><code>moves[i].length == 2</code></li>
84+
<li><code>0 &lt;= moves[i][j] &lt;= 2</code></li>
85+
<li>There are no repeated elements on <code>moves</code>.</li>
86+
<li><code>moves</code> follow the rules of tic tac toe.</li>
87+
</ul>
88+
89+
### Related Topics
90+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
91+
92+
### Hints
93+
<details>
94+
<summary>Hint 1</summary>
95+
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.
96+
</details>
97+
98+
<details>
99+
<summary>Hint 2</summary>
100+
Then if no one wins, the game is a draw iff the board is full, i.e. moves.length = 9 otherwise is pending.
101+
</details>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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-winner-on-a-tic-tac-toe-game "Find Winner on a Tic Tac Toe Game")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/count-square-submatrices-with-all-ones "Count Square Submatrices with All Ones")
11+
12+
## [1276. Number of Burgers with No Waste of Ingredients (Medium)](https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients "不浪费原料的汉堡制作方案")
13+
14+
<p>Given two integers <code>tomatoSlices</code>&nbsp;and <code>cheeseSlices</code>. The ingredients of different burgers are as follows:</p>
15+
16+
<ul>
17+
<li><strong>Jumbo Burger:</strong> 4 tomato slices&nbsp;and 1 cheese slice.</li>
18+
<li><strong>Small Burger:</strong> 2 Tomato slices&nbsp;and 1 cheese slice.</li>
19+
</ul>
20+
21+
<p>Return <code>[total_jumbo, total_small]</code> so that the number of remaining <code>tomatoSlices</code>&nbsp;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>&nbsp;and <code>cheeseSlices</code> equal to 0 return <code>[]</code>.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> tomatoSlices = 16, cheeseSlices = 7
28+
<strong>Output:</strong> [1,6]
29+
<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.
30+
</pre>
31+
32+
<p><strong>Example 2:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> tomatoSlices = 17, cheeseSlices = 4
36+
<strong>Output:</strong> []
37+
<strong>Explantion:</strong> There will be no way to use all ingredients to make small and jumbo burgers.
38+
</pre>
39+
40+
<p><strong>Example 3:</strong></p>
41+
42+
<pre>
43+
<strong>Input:</strong> tomatoSlices = 4, cheeseSlices = 17
44+
<strong>Output:</strong> []
45+
<strong>Explantion:</strong> Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.
46+
</pre>
47+
48+
<p><strong>Example 4:</strong></p>
49+
50+
<pre>
51+
<strong>Input:</strong> tomatoSlices = 0, cheeseSlices = 0
52+
<strong>Output:</strong> [0,0]
53+
</pre>
54+
55+
<p><strong>Example 5:</strong></p>
56+
57+
<pre>
58+
<strong>Input:</strong> tomatoSlices = 2, cheeseSlices = 1
59+
<strong>Output:</strong> [0,1]
60+
</pre>
61+
62+
<p>&nbsp;</p>
63+
<p><strong>Constraints:</strong></p>
64+
65+
<ul>
66+
<li><code>0 &lt;= tomatoSlices &lt;= 10^7</code></li>
67+
<li><code>0 &lt;= cheeseSlices &lt;= 10^7</code></li>
68+
</ul>
69+
70+
### Related Topics
71+
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
72+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
73+
74+
### Hints
75+
<details>
76+
<summary>Hint 1</summary>
77+
Can we have an answer if the number of tomatoes is odd ?
78+
</details>
79+
80+
<details>
81+
<summary>Hint 2</summary>
82+
If we have answer will be there multiple answers or just one answer ?
83+
</details>
84+
85+
<details>
86+
<summary>Hint 3</summary>
87+
Let us define number of jumbo burgers as X and number of small burgers as Y
88+
We have to find an x and y in this equation
89+
</details>
90+
91+
<details>
92+
<summary>Hint 4</summary>
93+
1. 4X + 2Y = tomato
94+
</details>
95+
96+
<details>
97+
<summary>Hint 5</summary>
98+
2. X + Y = cheese
99+
</details>

‎problems/number-of-ships-in-a-rectangle/README.md

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

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/delete-tree-nodes "Delete Tree Nodes")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/find-winner-on-a-tic-tac-toe-game"Find Winner on a Tic Tac Toe Game")
1111

1212
## [1274. Number of Ships in a Rectangle (Hard)](https://leetcode.com/problems/number-of-ships-in-a-rectangle "矩形内船只的数目")
1313

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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/count-square-submatrices-with-all-ones "Count Square Submatrices with All Ones")
9+
10+
Next >
11+
12+
## [1278. Palindrome Partitioning III (Hard)](https://leetcode.com/problems/palindrome-partitioning-iii "分割回文串 III")
13+
14+
<p>You are given a string&nbsp;<code>s</code> containing lowercase letters and an integer <code>k</code>. You need to :</p>
15+
16+
<ul>
17+
<li>First, change some characters of <code>s</code>&nbsp;to other lowercase English letters.</li>
18+
<li>Then divide <code>s</code>&nbsp;into <code>k</code> non-empty disjoint substrings such that each substring is palindrome.</li>
19+
</ul>
20+
21+
<p>Return the minimal number of characters that you need to change&nbsp;to divide the string.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> s = &quot;abc&quot;, k = 2
28+
<strong>Output:</strong> 1
29+
<strong>Explanation:</strong>&nbsp;You can split the string into &quot;ab&quot; and &quot;c&quot;, and change 1 character in &quot;ab&quot; to make it palindrome.
30+
</pre>
31+
32+
<p><strong>Example 2:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> s = &quot;aabbc&quot;, k = 3
36+
<strong>Output:</strong> 0
37+
<strong>Explanation:</strong>&nbsp;You can split the string into &quot;aa&quot;, &quot;bb&quot; and &quot;c&quot;, all of them are palindrome.</pre>
38+
39+
<p><strong>Example 3:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> s = &quot;leetcode&quot;, k = 8
43+
<strong>Output:</strong> 0
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
<p><strong>Constraints:</strong></p>
48+
49+
<ul>
50+
<li><code>1 &lt;= k &lt;= s.length &lt;= 100</code>.</li>
51+
<li><code>s</code>&nbsp;only contains lowercase English letters.</li>
52+
</ul>
53+
54+
### Related Topics
55+
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
56+
57+
### Hints
58+
<details>
59+
<summary>Hint 1</summary>
60+
For each substring calculate the minimum number of steps to make it palindrome and store it in a table.
61+
</details>
62+
63+
<details>
64+
<summary>Hint 2</summary>
65+
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.
66+
</details>

‎tag/array/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
| # | 题名 | 标签 | 难度 |
1111
| :-: | - | - | :-: |
12+
| 1277 | [统计全为 1 的正方形子矩阵](https://github.com/openset/leetcode/tree/master/problems/count-square-submatrices-with-all-ones) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Medium |
13+
| 1275 | [找出井字棋的获胜者](https://github.com/openset/leetcode/tree/master/problems/find-winner-on-a-tic-tac-toe-game) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | Easy |
1214
| 1267 | [统计参与通信的服务器](https://github.com/openset/leetcode/tree/master/problems/count-servers-that-communicate) | [[](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | Medium |
1315
| 1266 | [访问所有点的最小时间](https://github.com/openset/leetcode/tree/master/problems/minimum-time-visiting-all-points) | [[几何](https://github.com/openset/leetcode/tree/master/tag/geometry/README.md)] [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | Easy |
1416
| 1260 | [二维网格迁移](https://github.com/openset/leetcode/tree/master/problems/shift-2d-grid) | [[数组](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] | Easy |

‎tag/depth-first-search/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| # | 题名 | 标签 | 难度 |
1111
| :-: | - | - | :-: |
12+
| 1273 | [删除树节点](https://github.com/openset/leetcode/tree/master/problems/delete-tree-nodes) | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Medium |
1213
| 1254 | [统计封闭岛屿的数目](https://github.com/openset/leetcode/tree/master/problems/number-of-closed-islands) | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] | Medium |
1314
| 1245 | [树的直径](https://github.com/openset/leetcode/tree/master/problems/tree-diameter) 🔒 | [[](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)] [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[广度优先搜索](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)] | Medium |
1415
| 1242 | [多线程网页爬虫](https://github.com/openset/leetcode/tree/master/problems/web-crawler-multithreaded) 🔒 | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[广度优先搜索](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)] | Medium |

0 commit comments

Comments
(0)

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