class Solution {
public:
void sortColors(vector<int>& nums) {
if (nums.empty()) {
return;
}
int l = -1;
int r = nums.size();
int idx = 0;
while (idx < r) {
if (nums[idx] == 0) {
l++;
swap(nums[idx], nums[l]);
idx++;
} else if (nums[idx] == 1) {
idx++;
} else {
r--;
swap(nums[idx], nums[r]);
}
}
}
};
转载请注明原文地址:https://blackberry.8miu.com/read-34519.html