-
Notifications
You must be signed in to change notification settings - Fork 130
Add: new #725
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 #725
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
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
64 changes: 64 additions & 0 deletions
problems/delete-tree-nodes/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,64 @@ | ||
<!--|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-interval "Remove Interval") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-ships-in-a-rectangle "Number of Ships in a Rectangle") | ||
|
||
## [1273. Delete Tree Nodes (Medium)](https://leetcode.com/problems/delete-tree-nodes "删除树节点") | ||
|
||
<p>A tree rooted at node 0 is given as follows:</p> | ||
|
||
<ul> | ||
<li>The number of nodes is <code>nodes</code>;</li> | ||
<li>The value of the <code>i</code>-th node is <code>value[i]</code>;</li> | ||
<li>The parent of the <code>i</code>-th node is <code>parent[i]</code>.</li> | ||
</ul> | ||
|
||
<p>Remove every subtree whose sum of values of nodes is zero.</p> | ||
|
||
<p>After doing so, return the number of nodes remaining in the tree.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/07/02/1421_sample_1.PNG" style="width: 403px; height: 347px;" /></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1] | ||
<strong>Output:</strong> 2 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nodes <= 10^4</code></li> | ||
<li><code>-10^5 <= value[i] <= 10^5</code></li> | ||
<li><code>parent.length == nodes</code></li> | ||
<li><code>parent[0] == -1</code> which indicates that <code>0</code> is the root.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] | ||
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Traverse the tree using depth first search. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Find for every node the sum of values of its sub-tree. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
Traverse the tree again from the root and return once you reach a node with zero sum of values in its sub-tree. | ||
</details> |
61 changes: 61 additions & 0 deletions
problems/hexspeak/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,61 @@ | ||
<!--|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/all-people-report-to-the-given-manager "All People Report to the Given Manager") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/remove-interval "Remove Interval") | ||
|
||
## [1271. Hexspeak (Easy)](https://leetcode.com/problems/hexspeak "十六进制魔术数字") | ||
|
||
<p>A decimal number can be converted to its <em>Hexspeak representation</em> 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>. Such a representation is <em>valid</em> if and only if it consists only of the letters in the set <code>{"A", "B", "C", "D", "E", "F", "I", "O"}</code>.</p> | ||
|
||
<p>Given a string <code>num</code> representing a decimal integer <code>N</code>, return the Hexspeak representation of <code>N</code> if it is valid, otherwise return <code>"ERROR"</code>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> num = "257" | ||
<strong>Output:</strong> "IOI" | ||
<b>Explanation: </b> 257 is 101 in hexadecimal. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> num = "3" | ||
<strong>Output:</strong> "ERROR" | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= N <= 10^12</code></li> | ||
<li>There are no leading zeros in the given string.</li> | ||
<li>All answers must be in uppercase letters.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | ||
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Convert the given number to hexadecimal. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Replace all 0 and 1 with 'O' and 'I'. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
Check if the final string has any numerical digits. | ||
</details> |
62 changes: 62 additions & 0 deletions
problems/number-of-ships-in-a-rectangle/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,62 @@ | ||
<!--|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/delete-tree-nodes "Delete Tree Nodes") | ||
|
||
Next > | ||
|
||
## [1274. Number of Ships in a Rectangle (Hard)](https://leetcode.com/problems/number-of-ships-in-a-rectangle "矩形内船只的数目") | ||
|
||
<p><em>(This problem is an <strong>interactive problem</strong>.)</em></p> | ||
|
||
<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> | ||
|
||
<p>You have a function <code>Sea.hasShips(topRight, bottomLeft)</code> which takes two points as arguments and returns <code>true</code> if and only if there is at least one ship in the rectangle represented by the two points, including on the boundary.</p> | ||
|
||
<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. It is guaranteed that there are <strong>at most 10 ships</strong> in that rectangle.</p> | ||
|
||
<p>Submissions making <strong>more than 400 calls</strong> to <code>hasShips</code> will be judged <em>Wrong Answer</em>. Also, any solutions that attempt to circumvent the judge will result in disqualification.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example :</strong></p> | ||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/07/26/1445_example_1.PNG" style="width: 400px; height: 404px;" /></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> | ||
ships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0] | ||
<strong>Output:</strong> 3 | ||
<strong>Explanation:</strong> From [0,0] to [4,4] we can count 3 ships within the range. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li>On the input <code>ships</code> is only given to initialize the map internally. You must solve this problem "blindfolded". In other words, you must find the answer using the given <code>hasShips</code> API, without knowing the <code>ships</code> position.</li> | ||
<li><code>0 <= bottomLeft[0] <= topRight[0] <= 1000</code></li> | ||
<li><code>0 <= bottomLeft[1] <= topRight[1] <= 1000</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Divide and Conquer](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Use divide and conquer technique. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Divide the query rectangle into 4 rectangles. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
Use recursion to continue with the rectangles that has ships only. | ||
</details> |
49 changes: 49 additions & 0 deletions
problems/remove-interval/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,49 @@ | ||
<!--|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/hexspeak "Hexspeak") | ||
|
||
[Next >](https://github.com/openset/leetcode/tree/master/problems/delete-tree-nodes "Delete Tree Nodes") | ||
|
||
## [1272. Remove Interval (Medium)](https://leetcode.com/problems/remove-interval "删除区间") | ||
|
||
<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 <code>x</code> such that <code>a <= x < b</code>.</p> | ||
|
||
<p>We remove the intersections between any interval in <code>intervals</code> and the interval <code>toBeRemoved</code>.</p> | ||
|
||
<p>Return a <strong>sorted</strong> list of <code>intervals</code> after all such removals.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
<pre><strong>Input:</strong> intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6] | ||
<strong>Output:</strong> [[0,1],[6,7]] | ||
</pre><p><strong>Example 2:</strong></p> | ||
<pre><strong>Input:</strong> intervals = [[0,5]], toBeRemoved = [2,3] | ||
<strong>Output:</strong> [[0,2],[3,5]] | ||
</pre> | ||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= intervals.length <= 10^4</code></li> | ||
<li><code>-10^9 <= intervals[i][0] < intervals[i][1] <= 10^9</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | ||
[[Line Sweep](https://github.com/openset/leetcode/tree/master/tag/line-sweep/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Solve the problem for every interval alone. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Divide the problem into cases according to the position of the two intervals. | ||
</details> |
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.