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 3240b39

Browse files
author
Shuo
authored
Merge pull request #725 from openset/develop
Add: new
2 parents c9bcaa3 + eaf054b commit 3240b39

File tree

6 files changed

+241
-1
lines changed

6 files changed

+241
-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="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 |
66+
| <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 |
67+
| <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 |
68+
| <span id="1271">1271</span> | [Hexspeak](https://leetcode.com/problems/hexspeak "十六进制魔术数字") | [Go](https://github.com/openset/leetcode/tree/master/problems/hexspeak) | Easy |
6569
| <span id="1270">1270</span> | [All People Report to the Given Manager](https://leetcode.com/problems/all-people-report-to-the-given-manager) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/all-people-report-to-the-given-manager) | Medium |
6670
| <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 |
6771
| <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 |

‎problems/all-people-report-to-the-given-manager/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/number-of-ways-to-stay-in-the-same-place-after-some-steps "Number of Ways to Stay in the Same Place After Some Steps")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/hexspeak"Hexspeak")
1111

1212
## [1270. All People Report to the Given Manager (Medium)](https://leetcode.com/problems/all-people-report-to-the-given-manager "")
1313

‎problems/delete-tree-nodes/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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-interval "Remove Interval")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-ships-in-a-rectangle "Number of Ships in a Rectangle")
11+
12+
## [1273. Delete Tree Nodes (Medium)](https://leetcode.com/problems/delete-tree-nodes "删除树节点")
13+
14+
<p>A tree rooted at node 0 is given as follows:</p>
15+
16+
<ul>
17+
<li>The number of nodes is <code>nodes</code>;</li>
18+
<li>The value of the <code>i</code>-th node is <code>value[i]</code>;</li>
19+
<li>The parent of the <code>i</code>-th node is <code>parent[i]</code>.</li>
20+
</ul>
21+
22+
<p>Remove every subtree whose sum of values of nodes is zero.</p>
23+
24+
<p>After doing so, return the number of nodes remaining in the tree.</p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/07/02/1421_sample_1.PNG" style="width: 403px; height: 347px;" /></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1]
33+
<strong>Output:</strong> 2
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li><code>1 &lt;= nodes &lt;= 10^4</code></li>
41+
<li><code>-10^5 &lt;= value[i] &lt;= 10^5</code></li>
42+
<li><code>parent.length == nodes</code></li>
43+
<li><code>parent[0] == -1</code>&nbsp;which indicates that <code>0</code> is the root.</li>
44+
</ul>
45+
46+
### Related Topics
47+
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
48+
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
49+
50+
### Hints
51+
<details>
52+
<summary>Hint 1</summary>
53+
Traverse the tree using depth first search.
54+
</details>
55+
56+
<details>
57+
<summary>Hint 2</summary>
58+
Find for every node the sum of values of its sub-tree.
59+
</details>
60+
61+
<details>
62+
<summary>Hint 3</summary>
63+
Traverse the tree again from the root and return once you reach a node with zero sum of values in its sub-tree.
64+
</details>

‎problems/hexspeak/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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/all-people-report-to-the-given-manager "All People Report to the Given Manager")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/remove-interval "Remove Interval")
11+
12+
## [1271. Hexspeak (Easy)](https://leetcode.com/problems/hexspeak "十六进制魔术数字")
13+
14+
<p>A decimal number can be converted to its&nbsp;<em>Hexspeak representation</em>&nbsp;by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit <code>0</code> with the letter <code>O</code>, and the digit <code>1</code> with the letter <code>I</code>.&nbsp; Such a representation&nbsp;is <em>valid</em>&nbsp;if and only if it consists only of the letters in the set <code>{&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;I&quot;, &quot;O&quot;}</code>.</p>
15+
16+
<p>Given a string <code>num</code>&nbsp;representing a decimal integer <code>N</code>, return the Hexspeak representation of <code>N</code> if it is valid, otherwise return <code>&quot;ERROR&quot;</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> num = &quot;257&quot;
23+
<strong>Output:</strong> &quot;IOI&quot;
24+
<b>Explanation: </b> 257 is 101 in hexadecimal.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> num = &quot;3&quot;
31+
<strong>Output:</strong> &quot;ERROR&quot;
32+
</pre>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Constraints:</strong></p>
36+
37+
<ul>
38+
<li><code>1 &lt;= N &lt;= 10^12</code></li>
39+
<li>There are no leading zeros in the given string.</li>
40+
<li>All answers must be in uppercase letters.</li>
41+
</ul>
42+
43+
### Related Topics
44+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
45+
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]
46+
47+
### Hints
48+
<details>
49+
<summary>Hint 1</summary>
50+
Convert the given number to hexadecimal.
51+
</details>
52+
53+
<details>
54+
<summary>Hint 2</summary>
55+
Replace all 0 and 1 with 'O' and 'I'.
56+
</details>
57+
58+
<details>
59+
<summary>Hint 3</summary>
60+
Check if the final string has any numerical digits.
61+
</details>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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/delete-tree-nodes "Delete Tree Nodes")
9+
10+
Next >
11+
12+
## [1274. Number of Ships in a Rectangle (Hard)](https://leetcode.com/problems/number-of-ships-in-a-rectangle "矩形内船只的数目")
13+
14+
<p><em>(This problem is an&nbsp;<strong>interactive problem</strong>.)</em></p>
15+
16+
<p>On the sea represented by a cartesian plane, each ship is located at an integer point, and each integer point may contain at most 1 ship.</p>
17+
18+
<p>You have a function <code>Sea.hasShips(topRight, bottomLeft)</code> which takes two points&nbsp;as arguments and returns <code>true</code>&nbsp;if and only if there is at least one ship in the rectangle represented by the two points, including on the boundary.</p>
19+
20+
<p>Given two points, which are the top right and bottom left corners of a rectangle, return the number of ships present in that rectangle.&nbsp;&nbsp;It is guaranteed that there are <strong>at most 10 ships</strong> in that rectangle.</p>
21+
22+
<p>Submissions making <strong>more than 400 calls</strong> to&nbsp;<code>hasShips</code>&nbsp;will be judged <em>Wrong Answer</em>.&nbsp; Also, any solutions that attempt to circumvent the judge&nbsp;will result in disqualification.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example :</strong></p>
26+
27+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/07/26/1445_example_1.PNG" style="width: 400px; height: 404px;" /></p>
28+
29+
<pre>
30+
<strong>Input:</strong>
31+
ships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0]
32+
<strong>Output:</strong> 3
33+
<strong>Explanation:</strong> From [0,0] to [4,4] we can count 3 ships within the range.
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li>On the input <code>ships</code> is only given to initialize the map internally.&nbsp;You must solve this problem &quot;blindfolded&quot;. In other words, you must find the answer using the given <code>hasShips</code> API, without knowing the <code>ships</code>&nbsp;position.</li>
41+
<li><code>0 &lt;=&nbsp;bottomLeft[0]&nbsp;&lt;= topRight[0]&nbsp;&lt;= 1000</code></li>
42+
<li><code>0 &lt;=&nbsp;bottomLeft[1]&nbsp;&lt;= topRight[1]&nbsp;&lt;= 1000</code></li>
43+
</ul>
44+
45+
### Related Topics
46+
[[Divide and Conquer](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md)]
47+
48+
### Hints
49+
<details>
50+
<summary>Hint 1</summary>
51+
Use divide and conquer technique.
52+
</details>
53+
54+
<details>
55+
<summary>Hint 2</summary>
56+
Divide the query rectangle into 4 rectangles.
57+
</details>
58+
59+
<details>
60+
<summary>Hint 3</summary>
61+
Use recursion to continue with the rectangles that has ships only.
62+
</details>

‎problems/remove-interval/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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/hexspeak "Hexspeak")
9+
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/delete-tree-nodes "Delete Tree Nodes")
11+
12+
## [1272. Remove Interval (Medium)](https://leetcode.com/problems/remove-interval "删除区间")
13+
14+
<p>Given a <strong>sorted</strong> list of disjoint <code>intervals</code>, each interval <code>intervals[i] = [a, b]</code> represents the set of real numbers&nbsp;<code>x</code> such that&nbsp;<code>a &lt;= x &lt; b</code>.</p>
15+
16+
<p>We remove the intersections between any interval in <code>intervals</code> and the interval <code>toBeRemoved</code>.</p>
17+
18+
<p>Return a <strong>sorted</strong>&nbsp;list of <code>intervals</code> after all such removals.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
<pre><strong>Input:</strong> intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]
23+
<strong>Output:</strong> [[0,1],[6,7]]
24+
</pre><p><strong>Example 2:</strong></p>
25+
<pre><strong>Input:</strong> intervals = [[0,5]], toBeRemoved = [2,3]
26+
<strong>Output:</strong> [[0,2],[3,5]]
27+
</pre>
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>1 &lt;= intervals.length &lt;= 10^4</code></li>
33+
<li><code>-10^9 &lt;= intervals[i][0] &lt; intervals[i][1] &lt;= 10^9</code></li>
34+
</ul>
35+
36+
### Related Topics
37+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
38+
[[Line Sweep](https://github.com/openset/leetcode/tree/master/tag/line-sweep/README.md)]
39+
40+
### Hints
41+
<details>
42+
<summary>Hint 1</summary>
43+
Solve the problem for every interval alone.
44+
</details>
45+
46+
<details>
47+
<summary>Hint 2</summary>
48+
Divide the problem into cases according to the position of the two intervals.
49+
</details>

0 commit comments

Comments
(0)

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