A row of tiles is painted in three colours, written as numbers: 0 for red, 1 for white and 2 for blue. Rearrange the integer array nums so that all the reds come first, then all the whites, then all the blues.
Change nums itself and return nothing. The judge reads nums after your function finishes, and that is the output shown in each example.
Try it without calling a library sort: there are only three values, so you can do better than a general sort.
Three reds, two whites and two blues, grouped in that order.
A colour can be missing entirely: here there is no 0.
Constraints
1 <= nums.length <= 300nums[i] is 0, 1 or 2.With only three values you never need to compare two elements: you only need to know where the 0s end and where the 2s begin.