Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions problems/replace-words/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,33 @@

## 648. Replace Words (Medium)

<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'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>
<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>

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

<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>
<p>You need to output the sentence after the replacement.</p>

<p>
You need to output the sentence after the replacement.
</p>
<p><b>Example 1:</b></p>


<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> dict = ["cat", "bat", "rat"]
sentence = "the cattle was rattled by the battery"
<b>Output:</b> "the cat was rat by the bat"
<b>Input:</b> dict = [&quot;cat&quot;, &quot;bat&quot;, &quot;rat&quot;]
sentence = &quot;the cattle was rattled by the battery&quot;
<b>Output:</b> &quot;the cat was rat by the bat&quot;
</pre>
</p>

<p>&nbsp;</p>

<p><b>Note:</b></p>

<p><b>Note:</b><br>
<ol>
<li>The input will only have lower-case letters.</li>
<li> 1 <= dict words number <= 1000 </li>
<li> 1 <= sentence words number <= 1000 </li>
<li> 1 <= root length <= 100 </li>
<li> 1 <= sentence words length <= 1000 </li>
<li>The input will only have lower-case letters.</li>
<li>1 &lt;= dict words number &lt;= 1000</li>
<li>1 &lt;= sentence words number &lt;= 1000</li>
<li>1 &lt;= root length &lt;= 100</li>
<li>1 &lt;= sentence words length &lt;= 1000</li>
</ol>
</p>

<p>&nbsp;</p>

### Related Topics
[[Trie](https://github.com/openset/leetcode/tree/master/tag/trie/README.md)]
Expand Down
32 changes: 28 additions & 4 deletions problems/reverse-words-in-a-string/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,33 @@

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

<p><strong>Example:&nbsp;&nbsp;</strong></p>
<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> &quot;<code>the sky is blue</code>&quot;
<strong>Output:&nbsp;</strong>&quot;<code>blue is sky the</code>&quot;
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> &quot; &nbsp;hello world! &nbsp;&quot;
<strong>Output:&nbsp;</strong>&quot;world! hello&quot;
<strong>Explanation:</strong> Your reversed string should not contain leading or trailing spaces.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> &quot;<code>the sky is blue</code>&quot;,
<strong>Output:&nbsp;</strong>&quot;<code>blue is sky the</code>&quot;.
<strong>Input:</strong> &quot;a good &nbsp; example&quot;
<strong>Output:&nbsp;</strong>&quot;example good a&quot;
<strong>Explanation:</strong> You need to reduce multiple spaces between two words to a single space in the reversed string.
</pre>

<p>&nbsp;</p>

<p><strong>Note:</strong></p>

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

<p><strong>Follow up:&nbsp;</strong>For C programmers, try to solve it <em>in-place</em> in <em>O</em>(1) space.</p>
<p>&nbsp;</p>

<p><strong>Follow up:</strong></p>

<p>For C programmers, try to solve it <em>in-place</em> in <em>O</em>(1) extra space.</p>

### Related Topics
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]
Expand Down
33 changes: 22 additions & 11 deletions problems/shortest-distance-in-a-line/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@

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

Table <code>point</code> holds the x coordinate of some points on x-axis in a plane, which are all integers.</p>
Write a query to find the shortest distance between two points in these points.</p>

Table <code>point</code> holds the x coordinate of some points on x-axis in a plane, which are all integers.
<p>&nbsp;</p>
Write a query to find the shortest distance between two points in these points.

<p>&nbsp;</p>

<pre>
| x |
|-----|
| -1 |
| 0 |
| 2 |
</pre></p>

The shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below:</p>
</pre>

<p>&nbsp;</p>
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:

<p>&nbsp;</p>

<pre>
| shortest|
|---------|
| 1 |
</pre></p>

<b>Note:</b> Every point is unique, which means there is no duplicates in table <code>point</code>.</p>

<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>
</pre>

<p>&nbsp;</p>
<b>Note:</b> Every point is unique, which means there is no duplicates in table <code>point</code>.

<p>&nbsp;</p>
<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>&nbsp;</p>
28 changes: 19 additions & 9 deletions problems/shortest-distance-in-a-plane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,32 @@

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

Table <code>point_2d</code> holds the coordinates (x,y) of some unique points (more than two) in a plane.</p>
Write a query to find the shortest distance between these points rounded to 2 decimals.</p>

Table <code>point_2d</code> holds the coordinates (x,y) of some unique points (more than two) in a plane.
<p>&nbsp;</p>
Write a query to find the shortest distance between these points rounded to 2 decimals.

<p>&nbsp;</p>

<pre>
| x | y |
|----|----|
| -1 | -1 |
| 0 | 0 |
| -1 | -2 |
</pre></p>

The shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be:</p>
</pre>

<p>&nbsp;</p>
The shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be:

<p>&nbsp;</p>

<pre>
| shortest |
|----------|
| 1.00 |
</pre></p>

<b>Note:</b> The longest distance among all the points are less than 10000.</p>
</pre>

<p>&nbsp;</p>
<b>Note:</b> The longest distance among all the points are less than 10000.

<p>&nbsp;</p>
45 changes: 27 additions & 18 deletions problems/smallest-good-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,48 @@

## 483. Smallest Good Base (Hard)

<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>
<p>Now given a string representing n, you should return the smallest good base of n in string format. <br/></p>
<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>

<p>Now given a string representing n, you should return the smallest good base of n in string format.</p>

<p><b>Example 1:</b></p>

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> "13"
<b>Output:</b> "3"
<b>Input:</b> &quot;13&quot;
<b>Output:</b> &quot;3&quot;
<b>Explanation:</b> 13 base 3 is 111.
</pre>
</p>

<p><b>Example 2:</b><br />
<p>&nbsp;</p>

<p><b>Example 2:</b></p>

<pre>
<b>Input:</b> "4681"
<b>Output:</b> "8"
<b>Input:</b> &quot;4681&quot;
<b>Output:</b> &quot;8&quot;
<b>Explanation:</b> 4681 base 8 is 11111.
</pre>
</p>

<p><b>Example 3:</b><br />
<p>&nbsp;</p>

<p><b>Example 3:</b></p>

<pre>
<b>Input:</b> "1000000000000000000"
<b>Output:</b> "999999999999999999"
<b>Input:</b> &quot;1000000000000000000&quot;
<b>Output:</b> &quot;999999999999999999&quot;
<b>Explanation:</b> 1000000000000000000 base 999999999999999999 is 11.
</pre>
</p>

<p><b>Note:</b><br>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ol>
<li>The range of n is [3, 10^18].</li>
<li>The string representing n is always valid and will not have leading zeros.</li>
<li>The range of n is [3, 10^18].</li>
<li>The string representing n is always valid and will not have leading zeros.</li>
</ol>
</p>

<p>&nbsp;</p>

### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
Expand Down
15 changes: 8 additions & 7 deletions problems/sum-of-square-numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@

## 633. Sum of Square Numbers (Easy)

<p>
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.
</p>
<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>

<p><b>Example 1:</b></p>

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> 5
<b>Output:</b> True
<b>Explanation:</b> 1 * 1 + 2 * 2 = 5
</pre>
</p>

<p>&nbsp;</p>

<p><b>Example 2:</b></p>

<p><b>Example 2:</b><br />
<pre>
<b>Input:</b> 3
<b>Output:</b> False
</pre>
</p>

<p>&nbsp;</p>

### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
Expand Down
35 changes: 22 additions & 13 deletions problems/teemo-attacking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,45 @@

## 495. Teemo Attacking (Medium)

<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'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.
</p>
<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>

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

<p><b>Example 1:</b><br />
<p><b>Example 1:</b></p>

<pre>
<b>Input:</b> [1,4], 2
<b>Output:</b> 4
<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.
<b>Explanation:</b> 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.
</pre>
</p>

<p>&nbsp;</p>

<p><b>Example 2:</b></p>

<p><b>Example 2:</b><br />
<pre>
<b>Input:</b> [1,2], 2
<b>Output:</b> 3
<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.
<b>Explanation:</b> 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&#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.
So you finally need to output 3.
</pre>
</p>

<p>&nbsp;</p>

<p><b>Note:</b></p>

<p><b>Note:</b><br>
<ol>
<li>You may assume the length of given time series array won't exceed 10000.</li>
<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>
<li>You may assume the length of given time series array won&#39;t exceed 10000.</li>
<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>
</ol>
</p>

<p>&nbsp;</p>

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