Package g0001_0100.s0075_sort_colors
Class Solution
java.lang.Object
g0001_0100.s0075_sort_colors.Solution
75 - Sort Colors.<p>Medium</p>
<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="_top">in-place</a></strong> so that objects of the same color are adjacent, with the colors in the order red, white, and blue.</p>
<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>
<p>You must solve this problem without using the library’s sort function.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,0,2,1,1,0]</p>
<p><strong>Output:</strong> [0,0,1,1,2,2]</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [2,0,1]</p>
<p><strong>Output:</strong> [0,1,2]</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [0]</p>
<p><strong>Output:</strong> [0]</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> nums = [1]</p>
<p><strong>Output:</strong> [1]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 <= n <= 300</code></li>
<li><code>nums[i]</code> is <code>0</code>, <code>1</code>, or <code>2</code>.</li>
</ul>
<p><strong>Follow up:</strong> Could you come up with a one-pass algorithm using only constant extra space?</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
sortColors
public void sortColors(int[] nums)
-