dsa · medium
Sort Colors (0s, 1s, 2s)
GreyOrangeArrayTwo PointersSorting
Sort nums containing only 0, 1, 2 **in one pass** (Dutch national flag) and return it.
Arguments
nums— the input array of integers
**Example**
`` Input: [2,0,2,1,1,0] Output: [0,0,1,1,2,2] ``
Constraints
1 <= nums.length <= 300 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [2,0,2,1,1,0] Expected: [0,0,1,1,2,2]
Example 2
Input: [2,0,1] Expected: [0,1,2]