Given an array nums with n objects colored red (0), white (1), or blue (2), sort them in-place so that objects of the same color are adjacent, in the order red, white, and blue.
You must solve this problem without using the library's sort function.
Example 1:
Input: nums = [2, 0, 2, 1, 1, 0]
Output: [0, 0, 1, 1, 2, 2]
Explanation: The array is sorted so that all 0s (red) come first, then all 1s (white), then all 2s (blue).
Example 2:
Input: nums = [2, 0, 1]
Output: [0, 1, 2]
Explanation: Each color appears once; sorting yields [0, 1, 2].
Example 3:
Input: nums = [0]
Output: [0]
Explanation: A single-element array is already sorted.
n == nums.length1 <= n <= 300nums[i] is either 0, 1, or 2