Sort Colors
LeetCode 75 • Medium • Dutch National Flag
nums contains only 0 (red), 1 (white), 2 (blue). Sort in-place in one pass with three pointers: lo, mid, hi.
TimeO(n)
SpaceO(1)
Step0/0
0 red
1 white
2 blue
lo · mid · hi
Ready
Press Play or Step. Demo:
[2,0,2,1,1,0] → all reds, then whites, then blues.