```
class Solution {
public:
void sortColors(vector<int>& nums) {
int red = -1;
int blue = nums.size();
int i = 0;
while (i < blue) {
if (nums[i] == 0) {
red++;
swap(nums[i], nums[red]);
i++;
} else if (nums[i] == 2) {
blue--;
swap(nums[i], nums[blue]);
} else {
i++;
}
}
}
};
```