Skip to content

Commit 40885e7

Browse files
Create README - LeetHub
1 parent 4c1f183 commit 40885e7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

sort-colors/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<h2>75. Sort Colors</h2><h3>Medium</h3><hr><div><p>Given an array <code>nums</code> with <code>n</code> objects colored red, white, or blue, sort them <strong><a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> </strong>so that objects of the same color are adjacent, with the colors in the order red, white, and blue.</p>
2+
3+
<p>We will use the integers <code>0</code>, <code>1</code>, and <code>2</code> to represent the color red, white, and blue, respectively.</p>
4+
5+
<p>You must solve this problem without using the library's sort function.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong>Example 1:</strong></p>
9+
<pre><strong>Input:</strong> nums = [2,0,2,1,1,0]
10+
<strong>Output:</strong> [0,0,1,1,2,2]
11+
</pre><p><strong>Example 2:</strong></p>
12+
<pre><strong>Input:</strong> nums = [2,0,1]
13+
<strong>Output:</strong> [0,1,2]
14+
</pre><p><strong>Example 3:</strong></p>
15+
<pre><strong>Input:</strong> nums = [0]
16+
<strong>Output:</strong> [0]
17+
</pre><p><strong>Example 4:</strong></p>
18+
<pre><strong>Input:</strong> nums = [1]
19+
<strong>Output:</strong> [1]
20+
</pre>
21+
<p>&nbsp;</p>
22+
<p><strong>Constraints:</strong></p>
23+
24+
<ul>
25+
<li><code>n == nums.length</code></li>
26+
<li><code>1 &lt;= n &lt;= 300</code></li>
27+
<li><code>nums[i]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</li>
28+
</ul>
29+
30+
<p>&nbsp;</p>
31+
<p><strong>Follow up:</strong>&nbsp;Could you come up with a one-pass algorithm using only&nbsp;constant extra space?</p>
32+
</div>

0 commit comments

Comments
 (0)