```
public void sortColors(int[] nums) {
int red=0, white=0, blue=0;
for(int num : nums) {
if(num == 0) red++;
else if(num == 1) white++;
else if(num == 2) blue++;
}
int index = 0;
while(red-- > 0) {
nums[index++] = 0;
}
while(white-- > 0) {
nums[index++] = 1;
}
while(blue-- > 0) {
nums[index++] = 2;
}
}
```