Skip to content

Commit e3500ce

Browse files
author
Shuo
authored
Merge pull request #411 from openset/develop
Update: description
2 parents 00f6236 + 9495588 commit e3500ce

File tree

10 files changed

+194
-125
lines changed

10 files changed

+194
-125
lines changed

problems/replace-words/README.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,33 @@
1111

1212
## 648. Replace Words (Medium)
1313

14-
<p>
15-
In English, we have a concept called <code>root</code>, which can be followed by some other words to form another longer word - let's call this word <code>successor</code>. For example, the root <code>an</code>, followed by <code>other</code>, which can form another word <code>another</code>.
16-
</p>
14+
<p>In English, we have a concept called <code>root</code>, which can be followed by some other words to form another longer word - let&#39;s call this word <code>successor</code>. For example, the root <code>an</code>, followed by <code>other</code>, which can form another word <code>another</code>.</p>
1715

16+
<p>Now, given a dictionary consisting of many roots and a sentence. You need to replace all the <code>successor</code> in the sentence with the <code>root</code> forming it. If a <code>successor</code> has many <code>roots</code> can form it, replace it with the root with the shortest length.</p>
1817

19-
<p>
20-
Now, given a dictionary consisting of many roots and a sentence. You need to replace all the <code>successor</code> in the sentence with the <code>root</code> forming it. If a <code>successor</code> has many <code>roots</code> can form it, replace it with the root with the shortest length.
21-
</p>
18+
<p>You need to output the sentence after the replacement.</p>
2219

23-
<p>
24-
You need to output the sentence after the replacement.
25-
</p>
20+
<p><b>Example 1:</b></p>
2621

27-
28-
<p><b>Example 1:</b><br />
2922
<pre>
30-
<b>Input:</b> dict = ["cat", "bat", "rat"]
31-
sentence = "the cattle was rattled by the battery"
32-
<b>Output:</b> "the cat was rat by the bat"
23+
<b>Input:</b> dict = [&quot;cat&quot;, &quot;bat&quot;, &quot;rat&quot;]
24+
sentence = &quot;the cattle was rattled by the battery&quot;
25+
<b>Output:</b> &quot;the cat was rat by the bat&quot;
3326
</pre>
34-
</p>
3527

28+
<p>&nbsp;</p>
29+
30+
<p><b>Note:</b></p>
3631

37-
<p><b>Note:</b><br>
3832
<ol>
39-
<li>The input will only have lower-case letters.</li>
40-
<li> 1 <= dict words number <= 1000 </li>
41-
<li> 1 <= sentence words number <= 1000 </li>
42-
<li> 1 <= root length <= 100 </li>
43-
<li> 1 <= sentence words length <= 1000 </li>
33+
<li>The input will only have lower-case letters.</li>
34+
<li>1 &lt;= dict words number &lt;= 1000</li>
35+
<li>1 &lt;= sentence words number &lt;= 1000</li>
36+
<li>1 &lt;= root length &lt;= 100</li>
37+
<li>1 &lt;= sentence words length &lt;= 1000</li>
4438
</ol>
45-
</p>
39+
40+
<p>&nbsp;</p>
4641

4742
### Related Topics
4843
[[Trie](https://github.com/openset/leetcode/tree/master/tag/trie/README.md)]

problems/reverse-words-in-a-string/README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,33 @@
1313

1414
<p>Given an input string, reverse the string word by word.</p>
1515

16-
<p><strong>Example:&nbsp;&nbsp;</strong></p>
16+
<p>&nbsp;</p>
17+
18+
<p><strong>Example 1:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> &quot;<code>the sky is blue</code>&quot;
22+
<strong>Output:&nbsp;</strong>&quot;<code>blue is sky the</code>&quot;
23+
</pre>
24+
25+
<p><strong>Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> &quot; &nbsp;hello world! &nbsp;&quot;
29+
<strong>Output:&nbsp;</strong>&quot;world! hello&quot;
30+
<strong>Explanation:</strong> Your reversed string should not contain leading or trailing spaces.
31+
</pre>
32+
33+
<p><strong>Example 3:</strong></p>
1734

1835
<pre>
19-
<strong>Input:</strong> &quot;<code>the sky is blue</code>&quot;,
20-
<strong>Output:&nbsp;</strong>&quot;<code>blue is sky the</code>&quot;.
36+
<strong>Input:</strong> &quot;a good &nbsp; example&quot;
37+
<strong>Output:&nbsp;</strong>&quot;example good a&quot;
38+
<strong>Explanation:</strong> You need to reduce multiple spaces between two words to a single space in the reversed string.
2139
</pre>
2240

41+
<p>&nbsp;</p>
42+
2343
<p><strong>Note:</strong></p>
2444

2545
<ul>
@@ -28,7 +48,11 @@
2848
<li>You need to reduce multiple spaces between two words to a single space in the reversed string.</li>
2949
</ul>
3050

31-
<p><strong>Follow up:&nbsp;</strong>For C programmers, try to solve it <em>in-place</em> in <em>O</em>(1) space.</p>
51+
<p>&nbsp;</p>
52+
53+
<p><strong>Follow up:</strong></p>
54+
55+
<p>For C programmers, try to solve it <em>in-place</em> in <em>O</em>(1) extra space.</p>
3256

3357
### Related Topics
3458
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]

problems/shortest-distance-in-a-line/README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,35 @@
1111

1212
## 613. Shortest Distance in a Line (Easy)
1313

14-
Table <code>point</code> holds the x coordinate of some points on x-axis in a plane, which are all integers.</p>
15-
Write a query to find the shortest distance between two points in these points.</p>
16-
14+
Table <code>point</code> holds the x coordinate of some points on x-axis in a plane, which are all integers.
15+
<p>&nbsp;</p>
16+
Write a query to find the shortest distance between two points in these points.
17+
18+
<p>&nbsp;</p>
19+
1720
<pre>
1821
| x |
1922
|-----|
2023
| -1 |
2124
| 0 |
2225
| 2 |
23-
</pre></p>
24-
25-
The shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below:</p>
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
The shortest distance is &#39;1&#39; obviously, which is from point &#39;-1&#39; to &#39;0&#39;. So the output is as below:
30+
31+
<p>&nbsp;</p>
32+
2633
<pre>
2734
| shortest|
2835
|---------|
2936
| 1 |
30-
</pre></p>
31-
32-
<b>Note:</b> Every point is unique, which means there is no duplicates in table <code>point</code>.</p>
33-
34-
<b>Follow-up:</b> What if all these points have an id and are arranged from the left most to the right most of x axis?</p>
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<b>Note:</b> Every point is unique, which means there is no duplicates in table <code>point</code>.
41+
42+
<p>&nbsp;</p>
43+
<b>Follow-up:</b> What if all these points have an id and are arranged from the left most to the right most of x axis?
44+
45+
<p>&nbsp;</p>

problems/shortest-distance-in-a-plane/README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@
1111

1212
## 612. Shortest Distance in a Plane (Medium)
1313

14-
Table <code>point_2d</code> holds the coordinates (x,y) of some unique points (more than two) in a plane.</p>
15-
Write a query to find the shortest distance between these points rounded to 2 decimals.</p>
16-
14+
Table <code>point_2d</code> holds the coordinates (x,y) of some unique points (more than two) in a plane.
15+
<p>&nbsp;</p>
16+
Write a query to find the shortest distance between these points rounded to 2 decimals.
17+
18+
<p>&nbsp;</p>
19+
1720
<pre>
1821
| x | y |
1922
|----|----|
2023
| -1 | -1 |
2124
| 0 | 0 |
2225
| -1 | -2 |
23-
</pre></p>
24-
25-
The shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be:</p>
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
The shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be:
30+
31+
<p>&nbsp;</p>
32+
2633
<pre>
2734
| shortest |
2835
|----------|
2936
| 1.00 |
30-
</pre></p>
31-
32-
<b>Note:</b> The longest distance among all the points are less than 10000.</p>
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<b>Note:</b> The longest distance among all the points are less than 10000.
41+
42+
<p>&nbsp;</p>

problems/smallest-good-base/README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,48 @@
1111

1212
## 483. Smallest Good Base (Hard)
1313

14-
<p>For an integer n, we call k>=2 a <i><b>good base</b></i> of n, if all digits of n base k are 1.</p>
15-
<p>Now given a string representing n, you should return the smallest good base of n in string format. <br/></p>
14+
<p>For an integer n, we call k&gt;=2 a <i><b>good base</b></i> of n, if all digits of n base k are 1.</p>
15+
16+
<p>Now given a string representing n, you should return the smallest good base of n in string format.</p>
17+
18+
<p><b>Example 1:</b></p>
1619

17-
<p><b>Example 1:</b><br />
1820
<pre>
19-
<b>Input:</b> "13"
20-
<b>Output:</b> "3"
21+
<b>Input:</b> &quot;13&quot;
22+
<b>Output:</b> &quot;3&quot;
2123
<b>Explanation:</b> 13 base 3 is 111.
2224
</pre>
23-
</p>
2425

25-
<p><b>Example 2:</b><br />
26+
<p>&nbsp;</p>
27+
28+
<p><b>Example 2:</b></p>
29+
2630
<pre>
27-
<b>Input:</b> "4681"
28-
<b>Output:</b> "8"
31+
<b>Input:</b> &quot;4681&quot;
32+
<b>Output:</b> &quot;8&quot;
2933
<b>Explanation:</b> 4681 base 8 is 11111.
3034
</pre>
31-
</p>
3235

33-
<p><b>Example 3:</b><br />
36+
<p>&nbsp;</p>
37+
38+
<p><b>Example 3:</b></p>
39+
3440
<pre>
35-
<b>Input:</b> "1000000000000000000"
36-
<b>Output:</b> "999999999999999999"
41+
<b>Input:</b> &quot;1000000000000000000&quot;
42+
<b>Output:</b> &quot;999999999999999999&quot;
3743
<b>Explanation:</b> 1000000000000000000 base 999999999999999999 is 11.
3844
</pre>
39-
</p>
4045

41-
<p><b>Note:</b><br>
46+
<p>&nbsp;</p>
47+
48+
<p><b>Note:</b></p>
49+
4250
<ol>
43-
<li>The range of n is [3, 10^18].</li>
44-
<li>The string representing n is always valid and will not have leading zeros.</li>
51+
<li>The range of n is [3, 10^18].</li>
52+
<li>The string representing n is always valid and will not have leading zeros.</li>
4553
</ol>
46-
</p>
54+
55+
<p>&nbsp;</p>
4756

4857
### Related Topics
4958
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]

problems/sum-of-square-numbers/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,26 @@
1111

1212
## 633. Sum of Square Numbers (Easy)
1313

14-
<p>
15-
Given a non-negative integer <code>c</code>, your task is to decide whether there're two integers <code>a</code> and <code>b</code> such that a<sup>2</sup> + b<sup>2</sup> = c.
16-
</p>
14+
<p>Given a non-negative integer <code>c</code>, your task is to decide whether there&#39;re two integers <code>a</code> and <code>b</code> such that a<sup>2</sup> + b<sup>2</sup> = c.</p>
15+
16+
<p><b>Example 1:</b></p>
1717

18-
<p><b>Example 1:</b><br />
1918
<pre>
2019
<b>Input:</b> 5
2120
<b>Output:</b> True
2221
<b>Explanation:</b> 1 * 1 + 2 * 2 = 5
2322
</pre>
24-
</p>
2523

24+
<p>&nbsp;</p>
25+
26+
<p><b>Example 2:</b></p>
2627

27-
<p><b>Example 2:</b><br />
2828
<pre>
2929
<b>Input:</b> 3
3030
<b>Output:</b> False
3131
</pre>
32-
</p>
32+
33+
<p>&nbsp;</p>
3334

3435
### Related Topics
3536
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]

problems/teemo-attacking/README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,45 @@
1111

1212
## 495. Teemo Attacking (Medium)
1313

14-
<p>
15-
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 <b>ascending</b> 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.
16-
</p>
14+
<p>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&#39;s attacking <b>ascending</b> time series towards Ashe and the poisoning time duration per Teemo&#39;s attacking, you need to output the total time that Ashe is in poisoned condition.</p>
1715

1816
<p>You may assume that Teemo attacks at the very beginning of a specific time point, and makes Ashe be in poisoned condition immediately.</p>
1917

20-
<p><b>Example 1:</b><br />
18+
<p><b>Example 1:</b></p>
19+
2120
<pre>
2221
<b>Input:</b> [1,4], 2
2322
<b>Output:</b> 4
24-
<b>Explanation:</b> At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately. <br />This poisoned status will last 2 seconds until the end of time point 2. <br />And at time point 4, Teemo attacks Ashe again, and causes Ashe to be in poisoned status for another 2 seconds. <br />So you finally need to output 4.
23+
<b>Explanation:</b> At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately.
24+
This poisoned status will last 2 seconds until the end of time point 2.
25+
And at time point 4, Teemo attacks Ashe again, and causes Ashe to be in poisoned status for another 2 seconds.
26+
So you finally need to output 4.
2527
</pre>
26-
</p>
2728

29+
<p>&nbsp;</p>
30+
31+
<p><b>Example 2:</b></p>
2832

29-
<p><b>Example 2:</b><br />
3033
<pre>
3134
<b>Input:</b> [1,2], 2
3235
<b>Output:</b> 3
33-
<b>Explanation:</b> At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned. <br />This poisoned status will last 2 seconds until the end of time point 2. <br/>However, at the beginning of time point 2, Teemo attacks Ashe again who is already in poisoned status. <br/>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. <br/>So you finally need to output 3.
36+
<b>Explanation:</b> At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned.
37+
This poisoned status will last 2 seconds until the end of time point 2.
38+
However, at the beginning of time point 2, Teemo attacks Ashe again who is already in poisoned status.
39+
Since the poisoned status won&#39;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.
40+
So you finally need to output 3.
3441
</pre>
35-
</p>
3642

43+
<p>&nbsp;</p>
44+
45+
<p><b>Note:</b></p>
3746

38-
<p><b>Note:</b><br>
3947
<ol>
40-
<li>You may assume the length of given time series array won't exceed 10000.</li>
41-
<li>You may assume the numbers in the Teemo's attacking time series and his poisoning time duration per attacking are non-negative integers, which won't exceed 10,000,000.</li>
48+
<li>You may assume the length of given time series array won&#39;t exceed 10000.</li>
49+
<li>You may assume the numbers in the Teemo&#39;s attacking time series and his poisoning time duration per attacking are non-negative integers, which won&#39;t exceed 10,000,000.</li>
4250
</ol>
43-
</p>
51+
52+
<p>&nbsp;</p>
4453

4554
### Related Topics
4655
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

0 commit comments

Comments
 (0)