medium
Sort Colors (Dutch National Flag)
An array contains only the values 0, 1 and 2 representing three colors. Sort it in place in a single pass without using a library sort.
Constraints
- 1 ≤ n ≤ 300
- nums[i] ∈ {0, 1, 2}
Examples
in: nums = [2,0,2,1,1,0]
out: [0,0,1,1,2,2]
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.