原地排序:空间复杂度为1
class Solution {
public:void sortColors(vector<int>& nums) {if(0){//法一:单指针两个遍历int n=nums.size();int ptr=0;for(int i=0;i<n;i++){if(nums[i]==0){swap(nums[i],nums[ptr]);++ptr;}}for(int i=ptr;i<n;i++){if(nums[i]==1){swap(nums[i],nums[ptr]);++ptr;}}}else if(1){//双指针法int n=nums.size();int p0=0,p2=n-1;int i=0;while(i<=p2){if(nums[i]==0){swap(nums[i],nums[p0]);++p0;++i;}else if(nums[i]==1){++i;}else{swap(nums[i],nums[p2]);--p2;}} }return;}
};