From eaf054bea6c0a5e04a8d70c4e517e58a317f4813 Mon Sep 17 00:00:00 2001 From: openset Date: Sun, 1 Dec 2019 09:38:32 +0800 Subject: [PATCH] Add: new --- README.md | 4 ++ .../README.md | 2 +- problems/delete-tree-nodes/README.md | 64 +++++++++++++++++++ problems/hexspeak/README.md | 61 ++++++++++++++++++ .../number-of-ships-in-a-rectangle/README.md | 62 ++++++++++++++++++ problems/remove-interval/README.md | 49 ++++++++++++++ 6 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 problems/delete-tree-nodes/README.md create mode 100644 problems/hexspeak/README.md create mode 100644 problems/number-of-ships-in-a-rectangle/README.md create mode 100644 problems/remove-interval/README.md diff --git a/README.md b/README.md index 559a978ee..bdb4c4b56 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,10 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1274 | [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 | +| 1273 | [Delete Tree Nodes](https://leetcode.com/problems/delete-tree-nodes "删除树节点") | [Go](https://github.com/openset/leetcode/tree/master/problems/delete-tree-nodes) | Medium | +| 1272 | [Remove Interval](https://leetcode.com/problems/remove-interval "删除区间") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-interval) | Medium | +| 1271 | [Hexspeak](https://leetcode.com/problems/hexspeak "十六进制魔术数字") | [Go](https://github.com/openset/leetcode/tree/master/problems/hexspeak) | Easy | | 1270 | [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 | | 1269 | [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 | | 1268 | [Search Suggestions System](https://leetcode.com/problems/search-suggestions-system "搜索推荐系统") | [Go](https://github.com/openset/leetcode/tree/master/problems/search-suggestions-system) | Medium | diff --git a/problems/all-people-report-to-the-given-manager/README.md b/problems/all-people-report-to-the-given-manager/README.md index b7e1080ef..97f24169a 100644 --- a/problems/all-people-report-to-the-given-manager/README.md +++ b/problems/all-people-report-to-the-given-manager/README.md @@ -7,7 +7,7 @@ [< 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") -Next> +[Next>](https://github.com/openset/leetcode/tree/master/problems/hexspeak "Hexspeak") ## [1270. All People Report to the Given Manager (Medium)](https://leetcode.com/problems/all-people-report-to-the-given-manager "") diff --git a/problems/delete-tree-nodes/README.md b/problems/delete-tree-nodes/README.md new file mode 100644 index 000000000..4ad510520 --- /dev/null +++ b/problems/delete-tree-nodes/README.md @@ -0,0 +1,64 @@ + + + + + + + +[< 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 "删除树节点") + +

A tree rooted at node 0 is given as follows:

+ + + +

Remove every subtree whose sum of values of nodes is zero.

+ +

After doing so, return the number of nodes remaining in the tree.

+ + +

Example 1:

+ + + +
+Input: nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1]
+Output: 2
+
+ + +

Constraints:

+ + + +### 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 +
+Hint 1 +Traverse the tree using depth first search. +
+ +
+Hint 2 +Find for every node the sum of values of its sub-tree. +
+ +
+Hint 3 +Traverse the tree again from the root and return once you reach a node with zero sum of values in its sub-tree. +
diff --git a/problems/hexspeak/README.md b/problems/hexspeak/README.md new file mode 100644 index 000000000..05f0646e4 --- /dev/null +++ b/problems/hexspeak/README.md @@ -0,0 +1,61 @@ + + + + + + + +[< 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 "十六进制魔术数字") + +

A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit 0 with the letter O, and the digit 1 with the letter I. Such a representation is valid if and only if it consists only of the letters in the set {"A", "B", "C", "D", "E", "F", "I", "O"}.

+ +

Given a string num representing a decimal integer N, return the Hexspeak representation of N if it is valid, otherwise return "ERROR".

+ + +

Example 1:

+ +
+Input: num = "257"
+Output: "IOI"
+Explanation:  257 is 101 in hexadecimal.
+
+ +

Example 2:

+ +
+Input: num = "3"
+Output: "ERROR"
+
+ + +

Constraints:

+ + + +### 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 +
+Hint 1 +Convert the given number to hexadecimal. +
+ +
+Hint 2 +Replace all 0 and 1 with 'O' and 'I'. +
+ +
+Hint 3 +Check if the final string has any numerical digits. +
diff --git a/problems/number-of-ships-in-a-rectangle/README.md b/problems/number-of-ships-in-a-rectangle/README.md new file mode 100644 index 000000000..81831b555 --- /dev/null +++ b/problems/number-of-ships-in-a-rectangle/README.md @@ -0,0 +1,62 @@ + + + + + + + +[< 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 "矩形内船只的数目") + +

(This problem is an interactive problem.)

+ +

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.

+ +

You have a function Sea.hasShips(topRight, bottomLeft) which takes two points as arguments and returns true if and only if there is at least one ship in the rectangle represented by the two points, including on the boundary.

+ +

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 at most 10 ships in that rectangle.

+ +

Submissions making more than 400 calls to hasShips will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.

+ + +

Example :

+ + + +
+Input: 
+ships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0]
+Output: 3
+Explanation: From [0,0] to [4,4] we can count 3 ships within the range.
+
+ + +

Constraints:

+ + + +### Related Topics + [[Divide and Conquer](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md)] + +### Hints +
+Hint 1 +Use divide and conquer technique. +
+ +
+Hint 2 +Divide the query rectangle into 4 rectangles. +
+ +
+Hint 3 +Use recursion to continue with the rectangles that has ships only. +
diff --git a/problems/remove-interval/README.md b/problems/remove-interval/README.md new file mode 100644 index 000000000..693b9c100 --- /dev/null +++ b/problems/remove-interval/README.md @@ -0,0 +1,49 @@ + + + + + + + +[< 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 "删除区间") + +

Given a sorted list of disjoint intervals, each interval intervals[i] = [a, b] represents the set of real numbers x such that a <= x < b.

+ +

We remove the intersections between any interval in intervals and the interval toBeRemoved.

+ +

Return a sorted list of intervals after all such removals.

+ + +

Example 1:

+
Input: intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]
+Output: [[0,1],[6,7]]
+

Example 2:

+
Input: intervals = [[0,5]], toBeRemoved = [2,3]
+Output: [[0,2],[3,5]]
+
+ +

Constraints:

+ + + +### 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 +
+Hint 1 +Solve the problem for every interval alone. +
+ +
+Hint 2 +Divide the problem into cases according to the position of the two intervals. +

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