Skip to content

Commit 99ebde6

Browse files
author
Shuo
authored
Merge pull request #717 from openset/develop
Add: new
2 parents d53abc3 + ac0dda9 commit 99ebde6

File tree

32 files changed

+447
-47
lines changed

32 files changed

+447
-47
lines changed

Diff for: README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1269">1269</span> | [Number of Ways to Stay in the Same Place After Some Steps](https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps "停在原地的方案数") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps) | Hard |
66+
| <span id="1268">1268</span> | [Search Suggestions System](https://leetcode.com/problems/search-suggestions-system "搜索推荐系统") | [Go](https://github.com/openset/leetcode/tree/master/problems/search-suggestions-system) | Medium |
67+
| <span id="1267">1267</span> | [Count Servers that Communicate](https://leetcode.com/problems/count-servers-that-communicate "统计参与通信的服务器") | [Go](https://github.com/openset/leetcode/tree/master/problems/count-servers-that-communicate) | Medium |
68+
| <span id="1266">1266</span> | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points "访问所有点的最小时间") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-time-visiting-all-points) | Easy |
69+
| <span id="1265">1265</span> | [Print Immutable Linked List in Reverse](https://leetcode.com/problems/print-immutable-linked-list-in-reverse) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/print-immutable-linked-list-in-reverse) | Medium |
70+
| <span id="1264">1264</span> | [Page Recommendations](https://leetcode.com/problems/page-recommendations) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/page-recommendations) | Medium |
6571
| <span id="1263">1263</span> | [Minimum Moves to Move a Box to Their Target Location](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location "推箱子") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-moves-to-move-a-box-to-their-target-location) | Hard |
6672
| <span id="1262">1262</span> | [Greatest Sum Divisible by Three](https://leetcode.com/problems/greatest-sum-divisible-by-three "可被三整除的最大和") | [Go](https://github.com/openset/leetcode/tree/master/problems/greatest-sum-divisible-by-three) | Medium |
6773
| <span id="1261">1261</span> | [Find Elements in a Contaminated Binary Tree](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree "在受污染的二叉树中查找元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-elements-in-a-contaminated-binary-tree) | Medium |
6874
| <span id="1260">1260</span> | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid "二维网格迁移") | [Go](https://github.com/openset/leetcode/tree/master/problems/shift-2d-grid) | Easy |
69-
| <span id="1259">1259</span> | [Handshakes That Don't Cross](https://leetcode.com/problems/handshakes-that-dont-cross "不相交的握手") | [Go](https://github.com/openset/leetcode/tree/master/problems/handshakes-that-dont-cross) | Hard |
70-
| <span id="1258">1258</span> | [Synonymous Sentences](https://leetcode.com/problems/synonymous-sentences "近义词句子") | [Go](https://github.com/openset/leetcode/tree/master/problems/synonymous-sentences) | Medium |
71-
| <span id="1257">1257</span> | [Smallest Common Region](https://leetcode.com/problems/smallest-common-region "最小公共区域") | [Go](https://github.com/openset/leetcode/tree/master/problems/smallest-common-region) | Medium |
72-
| <span id="1256">1256</span> | [Encode Number](https://leetcode.com/problems/encode-number "加密数字") | [Go](https://github.com/openset/leetcode/tree/master/problems/encode-number) | Medium |
75+
| <span id="1259">1259</span> | [Handshakes That Don't Cross](https://leetcode.com/problems/handshakes-that-dont-cross "不相交的握手") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/handshakes-that-dont-cross) | Hard |
76+
| <span id="1258">1258</span> | [Synonymous Sentences](https://leetcode.com/problems/synonymous-sentences "近义词句子") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/synonymous-sentences) | Medium |
77+
| <span id="1257">1257</span> | [Smallest Common Region](https://leetcode.com/problems/smallest-common-region "最小公共区域") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/smallest-common-region) | Medium |
78+
| <span id="1256">1256</span> | [Encode Number](https://leetcode.com/problems/encode-number "加密数字") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/encode-number) | Medium |
7379
| <span id="1255">1255</span> | [Maximum Score Words Formed by Letters](https://leetcode.com/problems/maximum-score-words-formed-by-letters "得分最高的单词集合") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-score-words-formed-by-letters) | Hard |
7480
| <span id="1254">1254</span> | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands "统计封闭岛屿的数目") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-closed-islands) | Medium |
7581
| <span id="1253">1253</span> | [Reconstruct a 2-Row Binary Matrix](https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix "重构 2 行二进制矩阵") | [Go](https://github.com/openset/leetcode/tree/master/problems/reconstruct-a-2-row-binary-matrix) | Medium |
@@ -183,7 +189,7 @@ LeetCode Problems' Solutions
183189
| <span id="1145">1145</span> | [Binary Tree Coloring Game](https://leetcode.com/problems/binary-tree-coloring-game "二叉树着色游戏") | [Go](https://github.com/openset/leetcode/tree/master/problems/binary-tree-coloring-game) | Medium |
184190
| <span id="1144">1144</span> | [Decrease Elements To Make Array Zigzag](https://leetcode.com/problems/decrease-elements-to-make-array-zigzag "递减元素使数组呈锯齿状") | [Go](https://github.com/openset/leetcode/tree/master/problems/decrease-elements-to-make-array-zigzag) | Medium |
185191
| <span id="1143">1143</span> | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence "最长公共子序列") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-common-subsequence) | Medium |
186-
| <span id="1142">1142</span> | [User Activity for the Past 30 Days II](https://leetcode.com/problems/user-activity-for-the-past-30-days-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/user-activity-for-the-past-30-days-ii) | Easy |
192+
| <span id="1142">1142</span> | [User Activity for the Past 30 Days II](https://leetcode.com/problems/user-activity-for-the-past-30-days-ii "过去30天的用户活动 II") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/user-activity-for-the-past-30-days-ii) | Easy |
187193
| <span id="1141">1141</span> | [User Activity for the Past 30 Days I](https://leetcode.com/problems/user-activity-for-the-past-30-days-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/user-activity-for-the-past-30-days-i) | Easy |
188194
| <span id="1140">1140</span> | [Stone Game II](https://leetcode.com/problems/stone-game-ii "石子游戏 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/stone-game-ii) | Medium |
189195
| <span id="1139">1139</span> | [Largest 1-Bordered Square](https://leetcode.com/problems/largest-1-bordered-square "最大的以 1 为边界的正方形") | [Go](https://github.com/openset/leetcode/tree/master/problems/largest-1-bordered-square) | Medium |

Diff for: problems/count-servers-that-communicate/README.md

+72
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 <[email protected]> |-->
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-time-visiting-all-points "Minimum Time Visiting All Points")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/search-suggestions-system "Search Suggestions System")
11+
12+
## [1267. Count Servers that Communicate (Medium)](https://leetcode.com/problems/count-servers-that-communicate "统计参与通信的服务器")
13+
14+
<p>You are given a map of a server center, represented as a <code>m * n</code> integer matrix&nbsp;<code>grid</code>, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.<br />
15+
<br />
16+
Return the number of servers&nbsp;that communicate with any other server.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-6.jpg" style="width: 202px; height: 203px;" /></p>
22+
23+
<pre>
24+
<strong>Input:</strong> grid = [[1,0],[0,1]]
25+
<strong>Output:</strong> 0
26+
<b>Explanation:</b>&nbsp;No servers can communicate with others.</pre>
27+
28+
<p><strong>Example 2:</strong></p>
29+
30+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/11/13/untitled-diagram-4.jpg" style="width: 203px; height: 203px;" /></strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> grid = [[1,0],[1,1]]
34+
<strong>Output:</strong> 3
35+
<b>Explanation:</b>&nbsp;All three servers can communicate with at least one other server.
36+
</pre>
37+
38+
<p><strong>Example 3:</strong></p>
39+
40+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-1-3.jpg" style="width: 443px; height: 443px;" /></p>
41+
42+
<pre>
43+
<strong>Input:</strong> grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]
44+
<strong>Output:</strong> 4
45+
<b>Explanation:</b>&nbsp;The two servers in the first row can communicate with each other. The two servers in the third column can communicate with each other. The server at right bottom corner can&#39;t communicate with any other server.
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>m == grid.length</code></li>
53+
<li><code>n == grid[i].length</code></li>
54+
<li><code>1 &lt;= m &lt;= 250</code></li>
55+
<li><code>1 &lt;= n &lt;= 250</code></li>
56+
<li><code>grid[i][j] == 0 or 1</code></li>
57+
</ul>
58+
59+
### Related Topics
60+
[[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)]
61+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
62+
63+
### Hints
64+
<details>
65+
<summary>Hint 1</summary>
66+
Store number of computer in each row and column.
67+
</details>
68+
69+
<details>
70+
<summary>Hint 2</summary>
71+
Count all servers that are not isolated.
72+
</details>

Diff for: problems/design-linked-list/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/design-hashmap "Design HashMap")
99

10-
[Next >](https://github.com/openset/leetcode/tree/master/problems/insert-into-a-cyclic-sorted-list "Insert into a Cyclic Sorted List")
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/insert-into-a-sorted-circular-linked-list "Insert into a Sorted Circular Linked List")
1111

1212
## [707. Design Linked List (Medium)](https://leetcode.com/problems/design-linked-list "设计链表")
1313

Diff for: problems/insert-into-a-cyclic-sorted-list/insert_into_a_cyclic_sorted_list.go

-1
This file was deleted.

Diff for: problems/insert-into-a-cyclic-sorted-list/insert_into_a_cyclic_sorted_list_test.go

-1
This file was deleted.

Diff for: problems/insert-into-a-cyclic-sorted-list/README.md renamed to problems/insert-into-a-sorted-circular-linked-list/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](https://github.com/openset/leetcode/tree/master/problems/to-lower-case "To Lower Case")
1111

12-
## [708. Insert into a Cyclic Sorted List (Medium)](https://leetcode.com/problems/insert-into-a-cyclic-sorted-list "循环有序列表的插入")
12+
## [708. Insert into a Sorted Circular Linked List (Medium)](https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list "循环有序列表的插入")
1313

1414

1515

Diff for: problems/insertion-sort-list/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ With each iteration one element (red) is removed from the input data and inserte
5353

5454
### Similar Questions
5555
1. [Sort List](https://github.com/openset/leetcode/tree/master/problems/sort-list) (Medium)
56-
1. [Insert into a Cyclic Sorted List](https://github.com/openset/leetcode/tree/master/problems/insert-into-a-cyclic-sorted-list) (Medium)
56+
1. [Insert into a Sorted Circular Linked List](https://github.com/openset/leetcode/tree/master/problems/insert-into-a-sorted-circular-linked-list) (Medium)

Diff for: problems/logger-rate-limiter/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,35 @@
1111

1212
## [359. Logger Rate Limiter (Easy)](https://leetcode.com/problems/logger-rate-limiter "日志速率限制器")
1313

14+
<p>Design a logger system that receive stream of messages along with its timestamps, each message should be printed if and only if it is <b>not printed in the last 10 seconds</b>.</p>
1415

16+
<p>Given a message and a timestamp (in seconds granularity), return true if the message should be printed in the given timestamp, otherwise returns false.</p>
17+
18+
<p>It is possible that several messages arrive roughly at the same time.</p>
19+
20+
<p><b>Example:</b></p>
21+
22+
<pre>
23+
Logger logger = new Logger();
24+
25+
// logging string &quot;foo&quot; at timestamp 1
26+
logger.shouldPrintMessage(1, &quot;foo&quot;); returns true;
27+
28+
// logging string &quot;bar&quot; at timestamp 2
29+
logger.shouldPrintMessage(2,&quot;bar&quot;); returns true;
30+
31+
// logging string &quot;foo&quot; at timestamp 3
32+
logger.shouldPrintMessage(3,&quot;foo&quot;); returns false;
33+
34+
// logging string &quot;bar&quot; at timestamp 8
35+
logger.shouldPrintMessage(8,&quot;bar&quot;); returns false;
36+
37+
// logging string &quot;foo&quot; at timestamp 10
38+
logger.shouldPrintMessage(10,&quot;foo&quot;); returns false;
39+
40+
// logging string &quot;foo&quot; at timestamp 11
41+
logger.shouldPrintMessage(11,&quot;foo&quot;); returns true;
42+
</pre>
1543

1644
### Related Topics
1745
[[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)]

Diff for: problems/maximum-depth-of-n-ary-tree/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<pre>
2626
<strong>Input:</strong> root = [1,null,3,2,4,null,5,6]
2727
<strong>Output:</strong> 3
28-
<strong>Explanation:</strong> Representation of 3-ary tree.
2928
</pre>
3029

3130
<p><strong>Example 2:</strong></p>

Diff for: problems/minimum-moves-to-move-a-box-to-their-target-location/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/greatest-sum-divisible-by-three "Greatest Sum Divisible by Three")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/page-recommendations "Page Recommendations")
1111

1212
## [1263. Minimum Moves to Move a Box to Their Target Location (Hard)](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location "推箱子")
1313

14-
<p>Storekeeper is a&nbsp;game, in which the player pushes boxes around in a warehouse, trying to get them to target locations.</p>
14+
<p>Storekeeper is a&nbsp;game&nbsp;in which the player pushes boxes around in a warehouse&nbsp;trying to get them to target locations.</p>
1515

16-
<p>The game is represented by a <code>grid</code> of size&nbsp;<code>n<font face="sans-serif, Arial, Verdana, Trebuchet MS">*</font></code><code>m</code>, where each element is a wall, floor&nbsp;or a box.</p>
16+
<p>The game is represented by a <code>grid</code> of size&nbsp;<code>n<font face="sans-serif, Arial, Verdana, Trebuchet MS">*</font></code><code>m</code>, where each element is a wall, floor, or a box.</p>
1717

1818
<p>Your task is move the box <code>&#39;B&#39;</code> to the target position <code>&#39;T&#39;</code> under the following rules:</p>
1919

2020
<ul>
21-
<li>Player is represented by character <code>&#39;S&#39;</code>&nbsp;and&nbsp;can move up, down, left, right in the <code>grid</code> if its a floor (empy cell).</li>
21+
<li>Player is represented by character <code>&#39;S&#39;</code>&nbsp;and&nbsp;can move up, down, left, right in the <code>grid</code> if it is a floor (empy cell).</li>
2222
<li>Floor is represented by character <code>&#39;.&#39;</code> that means free cell to walk.</li>
2323
<li>Wall is represented by character <code>&#39;#&#39;</code> that means obstacle&nbsp;&nbsp;(impossible to walk there).&nbsp;</li>
2424
<li>There is only one box <code>&#39;B&#39;</code> and one&nbsp;target cell <code>&#39;T&#39;</code> in the <code>grid</code>.</li>

Diff for: problems/minimum-time-visiting-all-points/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
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/print-immutable-linked-list-in-reverse "Print Immutable Linked List in Reverse")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/count-servers-that-communicate "Count Servers that Communicate")
11+
12+
## [1266. Minimum Time Visiting All Points (Easy)](https://leetcode.com/problems/minimum-time-visiting-all-points "访问所有点的最小时间")
13+
14+
<p>On a plane there are <code>n</code> points with integer coordinates <code>points[i] = [xi, yi]</code>. Your task is to find the minimum time in seconds to visit all points.</p>
15+
16+
<p>You can move according to the next rules:</p>
17+
18+
<ul>
19+
<li>In one second always you can either move vertically, horizontally by one unit or diagonally (it means to move one unit vertically and one unit horizontally in one second).</li>
20+
<li>You have to visit the points in the same order as they appear in the array.</li>
21+
</ul>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
<img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/1626_example_1.PNG" style="width: 500px; height: 428px;" />
26+
<pre>
27+
<strong>Input:</strong> points = [[1,1],[3,4],[-1,0]]
28+
<strong>Output:</strong> 7
29+
<strong>Explanation: </strong>One optimal path is <strong>[1,1]</strong> -&gt; [2,2] -&gt; [3,3] -&gt; <strong>[3,4] </strong>-&gt; [2,3] -&gt; [1,2] -&gt; [0,1] -&gt; <strong>[-1,0]</strong>
30+
Time from [1,1] to [3,4] = 3 seconds
31+
Time from [3,4] to [-1,0] = 4 seconds
32+
Total time = 7 seconds</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> points = [[3,2],[-2,2]]
38+
<strong>Output:</strong> 5
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>points.length == n</code></li>
46+
<li><code>1 &lt;= n&nbsp;&lt;= 100</code></li>
47+
<li><code>points[i].length == 2</code></li>
48+
<li><code>-1000&nbsp;&lt;= points[i][0], points[i][1]&nbsp;&lt;= 1000</code></li>
49+
</ul>
50+
51+
### Related Topics
52+
[[Geometry](https://github.com/openset/leetcode/tree/master/tag/geometry/README.md)]
53+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
54+
55+
### Hints
56+
<details>
57+
<summary>Hint 1</summary>
58+
To walk from point A to point B there will be an optimal strategy to walk ?
59+
</details>
60+
61+
<details>
62+
<summary>Hint 2</summary>
63+
Advance in diagonal as possible then after that go in straight line.
64+
</details>
65+
66+
<details>
67+
<summary>Hint 3</summary>
68+
Repeat the process until visiting all the points.
69+
</details>

0 commit comments

Comments
 (0)