diff --git a/problems/replace-words/README.md b/problems/replace-words/README.md index dd750cfdc..21418bedd 100644 --- a/problems/replace-words/README.md +++ b/problems/replace-words/README.md @@ -11,38 +11,33 @@ ## 648. Replace Words (Medium) -
-In English, we have a concept called root
, which can be followed by some other words to form another longer word - let's call this word successor
. For example, the root an
, followed by other
, which can form another word another
.
-
In English, we have a concept called root
, which can be followed by some other words to form another longer word - let's call this word successor
. For example, the root an
, followed by other
, which can form another word another
.
Now, given a dictionary consisting of many roots and a sentence. You need to replace all the successor
in the sentence with the root
forming it. If a successor
has many roots
can form it, replace it with the root with the shortest length.
-Now, given a dictionary consisting of many roots and a sentence. You need to replace all the successor
in the sentence with the root
forming it. If a successor
has many roots
can form it, replace it with the root with the shortest length.
-
You need to output the sentence after the replacement.
--You need to output the sentence after the replacement. -
+Example 1:
- -Example 1:
-Input: dict = ["cat", "bat", "rat"] -sentence = "the cattle was rattled by the battery" -Output: "the cat was rat by the bat" +Input: dict = ["cat", "bat", "rat"] +sentence = "the cattle was rattled by the battery" +Output: "the cat was rat by the bat"- +
+ +
Note:
-Note:
### Related Topics [[Trie](https://github.com/openset/leetcode/tree/master/tag/trie/README.md)] diff --git a/problems/reverse-words-in-a-string/README.md b/problems/reverse-words-in-a-string/README.md index 300fe3ead..630647882 100644 --- a/problems/reverse-words-in-a-string/README.md +++ b/problems/reverse-words-in-a-string/README.md @@ -13,13 +13,33 @@
Given an input string, reverse the string word by word.
-Example:
++ +
Example 1:
+ ++Input: "+ +the sky is blue
" +Output: "blue is sky the
" +
Example 2:
+ ++Input: " hello world! " +Output: "world! hello" +Explanation: Your reversed string should not contain leading or trailing spaces. ++ +
Example 3:
-Input: "+the sky is blue
", -Output: "blue is sky the
". +Input: "a good example" +Output: "example good a" +Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.
+
Note:
Follow up: For C programmers, try to solve it in-place in O(1) space.
++ +
Follow up:
+ +For C programmers, try to solve it in-place in O(1) extra space.
### Related Topics [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] diff --git a/problems/shortest-distance-in-a-line/README.md b/problems/shortest-distance-in-a-line/README.md index bd716c3b3..7b6be68a7 100644 --- a/problems/shortest-distance-in-a-line/README.md +++ b/problems/shortest-distance-in-a-line/README.md @@ -11,24 +11,35 @@ ## 613. Shortest Distance in a Line (Easy) -Tablepoint
holds the x coordinate of some points on x-axis in a plane, which are all integers.
-Write a query to find the shortest distance between two points in these points.
-
+Table point
holds the x coordinate of some points on x-axis in a plane, which are all integers.
++Write a query to find the shortest distance between two points in these points. + +
+
| x | |-----| | -1 | | 0 | | 2 | -- -The shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below: + + +
+The shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below: + +
+
| shortest| |---------| | 1 | -- -Note: Every point is unique, which means there is no duplicates in table
point
.
-
-Follow-up: What if all these points have an id and are arranged from the left most to the right most of x axis?
+
+
++Note: Every point is unique, which means there is no duplicates in table
point
.
+
++Follow-up: What if all these points have an id and are arranged from the left most to the right most of x axis? + +
diff --git a/problems/shortest-distance-in-a-plane/README.md b/problems/shortest-distance-in-a-plane/README.md index 8265c218b..d872d7c81 100644 --- a/problems/shortest-distance-in-a-plane/README.md +++ b/problems/shortest-distance-in-a-plane/README.md @@ -11,22 +11,32 @@ ## 612. Shortest Distance in a Plane (Medium) -Table
point_2d
holds the coordinates (x,y) of some unique points (more than two) in a plane.
-Write a query to find the shortest distance between these points rounded to 2 decimals.
-
+Table point_2d
holds the coordinates (x,y) of some unique points (more than two) in a plane.
++Write a query to find the shortest distance between these points rounded to 2 decimals. + +
+
| x | y | |----|----| | -1 | -1 | | 0 | 0 | | -1 | -2 | -- -The shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be: + + +
+The shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be: + +
+
| shortest | |----------| | 1.00 | -- -Note: The longest distance among all the points are less than 10000. + + +
+Note: The longest distance among all the points are less than 10000. + +
diff --git a/problems/smallest-good-base/README.md b/problems/smallest-good-base/README.md index ce87eb5f7..c5042248a 100644 --- a/problems/smallest-good-base/README.md +++ b/problems/smallest-good-base/README.md @@ -11,39 +11,48 @@ ## 483. Smallest Good Base (Hard) -
For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1.
-Now given a string representing n, you should return the smallest good base of n in string format.
For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1.
+ +Now given a string representing n, you should return the smallest good base of n in string format.
+ +Example 1:
-Example 1:
-Input: "13" -Output: "3" +Input: "13" +Output: "3" Explanation: 13 base 3 is 111.- -
Example 2:
+
+ +
Example 2:
+-Input: "4681" -Output: "8" +Input: "4681" +Output: "8" Explanation: 4681 base 8 is 11111.- -
Example 3:
+
+ +
Example 3:
+-Input: "1000000000000000000" -Output: "999999999999999999" +Input: "1000000000000000000" +Output: "999999999999999999" Explanation: 1000000000000000000 base 999999999999999999 is 11.- -
Note:
+
+ +
Note:
+### Related Topics [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] diff --git a/problems/sum-of-square-numbers/README.md b/problems/sum-of-square-numbers/README.md index fe9f2a0ac..17fe235b9 100644 --- a/problems/sum-of-square-numbers/README.md +++ b/problems/sum-of-square-numbers/README.md @@ -11,25 +11,26 @@ ## 633. Sum of Square Numbers (Easy) -
-Given a non-negative integer c
, your task is to decide whether there're two integers a
and b
such that a2 + b2 = c.
-
Given a non-negative integer c
, your task is to decide whether there're two integers a
and b
such that a2 + b2 = c.
Example 1:
-Example 1:
Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5- +
+ +
Example 2:
-Example 2:
Input: 3 Output: False- + +
### Related Topics [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] diff --git a/problems/teemo-attacking/README.md b/problems/teemo-attacking/README.md index cd9590cc3..b7528e0e9 100644 --- a/problems/teemo-attacking/README.md +++ b/problems/teemo-attacking/README.md @@ -11,36 +11,45 @@ ## 495. Teemo Attacking (Medium) -
-In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, you need to output the total time that Ashe is in poisoned condition. -
+In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, you need to output the total time that Ashe is in poisoned condition.
You may assume that Teemo attacks at the very beginning of a specific time point, and makes Ashe be in poisoned condition immediately.
-Example 1:
+
Example 1:
+Input: [1,4], 2 Output: 4 -Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately.- +
This poisoned status will last 2 seconds until the end of time point 2.
And at time point 4, Teemo attacks Ashe again, and causes Ashe to be in poisoned status for another 2 seconds.
So you finally need to output 4. +Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately. +This poisoned status will last 2 seconds until the end of time point 2. +And at time point 4, Teemo attacks Ashe again, and causes Ashe to be in poisoned status for another 2 seconds. +So you finally need to output 4.
+ +
Example 2:
-Example 2:
Input: [1,2], 2 Output: 3 -Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned.- +
This poisoned status will last 2 seconds until the end of time point 2.
However, at the beginning of time point 2, Teemo attacks Ashe again who is already in poisoned status.
Since the poisoned status won't add up together, though the second poisoning attack will still work at time point 2, it will stop at the end of time point 3.
So you finally need to output 3. +Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned. +This poisoned status will last 2 seconds until the end of time point 2. +However, at the beginning of time point 2, Teemo attacks Ashe again who is already in poisoned status. +Since the poisoned status won't add up together, though the second poisoning attack will still work at time point 2, it will stop at the end of time point 3. +So you finally need to output 3.
+ +
Note:
-Note:
### Related Topics [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] diff --git a/problems/tree-node/README.md b/problems/tree-node/README.md index 2eaf2349e..46b369cd5 100644 --- a/problems/tree-node/README.md +++ b/problems/tree-node/README.md @@ -11,10 +11,8 @@ ## 608. Tree Node (Medium) -
-Given a table tree
, id is identifier of the tree node and p_id is its parent node's id.
-
Given a table tree
, id is identifier of the tree node and p_id is its parent node's id.
+----+------+ | id | p_id | @@ -26,14 +24,19 @@ Given a tabletree
, id is identifier of the tree node and - -Each node in the tree can be one of three types: -Leaf: if the node is a leaf node. -Root: if the node is the root of the tree. -Inner: If the node is neither a leaf node nor a root node. - -Write a query to print the node id and the type of the node. Sort your output by the node id. The result for the above sample is: - +Each node in the tree can be one of three types: + ++
+ +- Leaf: if the node is a leaf node.
+- Root: if the node is the root of the tree.
+- Inner: If the node is neither a leaf node nor a root node.
++Write a query to print the node id and the type of the node. Sort your output by the node id. The result for the above sample is: + +
+
+----+------+ | id | Type | @@ -45,32 +48,31 @@ Write a query to print the node id and the type of the node. Sort your output by | 5 | Leaf | +----+------+- - --Explanation -
--
+ ++ +
Explanation
+ ++ +
+
1 / \ 2 3 / \ 4 5- -
-Note -
--If there is only one node on the tree, you only need to output its root attributes. -
+Note
+If there is only one node on the tree, you only need to output its root attributes.
+triangle
holds the length of the three sides x, y and z.
-
+A pupil Tim gets homework to identify whether three line segments could possibly form a triangle.
++However, this assignment is very heavy because there are hundreds of records to calculate. + +
+Could you help Tim by writing a query to judge whether these three sides can form a triangle, assuming table
triangle
holds the length of the three sides x, y and z.
+
++
| x | y | z | |----|----|----| | 13 | 15 | 30 | | 10 | 20 | 15 |- For the sample data above, your query should return the follow result: +
| x | y | z | triangle | |----|----|----|----------| diff --git a/problems/two-sum-iv-input-is-a-bst/README.md b/problems/two-sum-iv-input-is-a-bst/README.md index 012c6773b..69ba7dac9 100644 --- a/problems/two-sum-iv-input-is-a-bst/README.md +++ b/problems/two-sum-iv-input-is-a-bst/README.md @@ -13,7 +13,8 @@Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.
-Example 1:
+Example 1:
+Input: 5 @@ -26,10 +27,11 @@ Target = 9 Output: True- ++ +
Example 2:
-Example 2:
Input: 5 @@ -42,7 +44,8 @@ Target = 28 Output: False- + +### Related Topics [[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]