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
38 changes: 19 additions & 19 deletions problems/detect-capital/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,38 @@

## 520. Detect Capital (Easy)

<p>
Given a word, you need to judge whether the usage of capitals in it is right or not.
</p>
<p>Given a word, you need to judge whether the usage of capitals in it is right or not.</p>

<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p>

<p>
We define the usage of capitals in a word to be right when one of the following cases holds:
<ol>
<li>All letters in this word are capitals, like "USA".</li>
<li>All letters in this word are not capitals, like "leetcode".</li>
<li>Only the first letter in this word is capital if it has more than one letter, like "Google".</li>
<li>All letters in this word are capitals, like &quot;USA&quot;.</li>
<li>All letters in this word are not capitals, like &quot;leetcode&quot;.</li>
<li>Only the first letter in this word is capital, like &quot;Google&quot;.</li>
</ol>
Otherwise, we define that this word doesn't use capitals in a right way.
</p>
Otherwise, we define that this word doesn&#39;t use capitals in a right way.

<p>&nbsp;</p>

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

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> "USA"
<b>Input:</b> &quot;USA&quot;
<b>Output:</b> True
</pre>
</p>

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

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

<pre>
<b>Input:</b> "FlaG"
<b>Input:</b> &quot;FlaG&quot;
<b>Output:</b> False
</pre>
</p>

<p><b>Note:</b>
The input will be a non-empty word consisting of uppercase and lowercase latin letters.
</p>
<p>&nbsp;</p>

<p><b>Note:</b> The input will be a non-empty word consisting of uppercase and lowercase latin letters.</p>

### Related Topics
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]
75 changes: 31 additions & 44 deletions problems/falling-squares/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,52 @@
## 699. Falling Squares (Hard)

<p>On an infinite number line (x-axis), we drop given squares in the order they are given.</p>

<p>The <code>i</code>-th square dropped (<code>positions[i] = (left, side_length)</code>) is a square with the left-most point being <code>positions[i][0]</code> and sidelength <code>positions[i][1]</code>.</p>
<p>The square is dropped with the bottom edge parallel to the number line, and from a higher height than all currently landed squares. We wait for each square to stick before dropping the next.</p>
<p>The squares are infinitely sticky on their bottom edge, and will remain fixed to any positive length surface they touch (either the number line or another square). Squares dropped adjacent to each other will not stick together prematurely.</p>

<br>
<p>Return a list <code>ans</code> of heights. Each height <code>ans[i]</code> represents the current highest height of any square we have dropped, after dropping squares represented by <code>positions[0], positions[1], ..., positions[i]</code>.
</p>
<p>The square is dropped with the bottom edge parallel to the number line, and from a higher height than all currently landed squares. We wait for each square to stick before dropping the next.</p>

<p>The squares are infinitely sticky on their bottom edge, and will remain fixed to any positive length surface they touch (either the number line or another square). Squares dropped adjacent to each other will not stick together prematurely.</p>
&nbsp;

<p>Return a list <code>ans</code> of heights. Each height <code>ans[i]</code> represents the current highest height of any square we have dropped, after dropping squares represented by <code>positions[0], positions[1], ..., positions[i]</code>.</p>

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

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> [[1, 2], [2, 3], [6, 1]]
<b>Output:</b> [2, 5, 5]
<b>Explanation:</b>
<p>
After the first drop of <code>positions[0] = [1, 2]:
_aa
_aa
-------
</code>The maximum height of any square is 2.
</p><p>
After the second drop of <code>positions[1] = [2, 3]:
__aaa
__aaa
__aaa
_aa__
_aa__
--------------
</code>The maximum height of any square is 5.
The larger square stays on top of the smaller square despite where its center
of gravity is, because squares are infinitely sticky on their bottom edge.
</p><p>
After the third drop of <code>positions[1] = [6, 1]:
__aaa
__aaa
__aaa
_aa
_aa___a
--------------
</code>The maximum height of any square is still 5.

Thus, we return an answer of <code>[2, 5, 5]</code>.
</pre>
</p>

<br>
<p>After the first drop of <code>positions[0] = [1, 2]: _aa _aa ------- </code>The maximum height of any square is 2.</p>

<p>After the second drop of <code>positions[1] = [2, 3]: __aaa __aaa __aaa _aa__ _aa__ -------------- </code>The maximum height of any square is 5. The larger square stays on top of the smaller square despite where its center of gravity is, because squares are infinitely sticky on their bottom edge.</p>

<p>After the third drop of <code>positions[1] = [6, 1]: __aaa __aaa __aaa _aa _aa___a -------------- </code>The maximum height of any square is still 5. Thus, we return an answer of <code>[2, 5, 5]</code>.</p>

<p>&nbsp;</p>
&nbsp;

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

<p><b>Example 2:</b><br />
<pre>
<b>Input:</b> [[100, 100], [200, 100]]
<b>Output:</b> [100, 100]
<b>Explanation:</b> Adjacent squares don't get stuck prematurely - only their bottom edge can stick to surfaces.
<b>Explanation:</b> Adjacent squares don&#39;t get stuck prematurely - only their bottom edge can stick to surfaces.
</pre>
</p>

<p><b>Note:</b>
<li><code>1 <= positions.length <= 1000</code>.</li>
<li><code>1 <= positions[i][0] <= 10^8</code>.</li>
<li><code>1 <= positions[i][1] <= 10^6</code>.</li>
</p>
<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= positions.length &lt;= 1000</code>.</li>
<li><code>1 &lt;= positions[i][0] &lt;= 10^8</code>.</li>
<li><code>1 &lt;= positions[i][1] &lt;= 10^6</code>.</li>
</ul>

<p>&nbsp;</p>

### Related Topics
[[Segment Tree](https://github.com/openset/leetcode/tree/master/tag/segment-tree/README.md)]
Expand Down
18 changes: 9 additions & 9 deletions problems/lru-cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@

## 146. LRU Cache (Hard)

<p>
Design and implement a data structure for <a href="https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU" target="_blank">Least Recently Used (LRU) cache</a>. It should support the following operations: <code>get</code> and <code>put</code>.
</p>
<p>Design and implement a data structure for <a href="https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU" target="_blank">Least Recently Used (LRU) cache</a>. It should support the following operations: <code>get</code> and <code>put</code>.</p>

<p>
<code>get(key)</code> - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.<br>
<code>put(key, value)</code> - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
</p>
<p><code>get(key)</code> - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.<br />
<code>put(key, value)</code> - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.</p>

<p>The cache is initialized with a <strong>positive</strong> capacity.</p>

<p><b>Follow up:</b><br />
Could you do both operations in <b>O(1)</b> time complexity?</p>

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

<pre>
LRUCache cache = new LRUCache( 2 /* capacity */ );

Expand All @@ -37,7 +36,8 @@ cache.get(1); // returns -1 (not found)
cache.get(3); // returns 3
cache.get(4); // returns 4
</pre>
</p>

<p>&nbsp;</p>

### Related Topics
[[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)]
Expand Down
10 changes: 6 additions & 4 deletions problems/minimum-number-of-arrows-to-burst-balloons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

## 452. Minimum Number of Arrows to Burst Balloons (Medium)

<p>There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 10<sup>4</sup> balloons.</p>
<p>There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it&#39;s horizontal, y-coordinates don&#39;t matter and hence the x-coordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 10<sup>4</sup> balloons.</p>

<p>An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with x<sub>start</sub> and x<sub>end</sub> bursts by an arrow shot at x if x<sub>start</sub> &le; x &le; x<sub>end</sub>. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons. </p>
<p>An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with x<sub>start</sub> and x<sub>end</sub> bursts by an arrow shot at x if x<sub>start</sub> &le; x &le; x<sub>end</sub>. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons.</p>

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

<p><b>Example:</b>
<pre>
<b>Input:</b>
[[10,16], [2,8], [1,6], [7,12]]
Expand All @@ -26,7 +27,8 @@
<b>Explanation:</b>
One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons).
</pre>
</p>

<p>&nbsp;</p>

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