题目:
代码:
class Solution {
public void sortColors(int[] nums) {
int left=0;
int right=nums.length-1;
int cur=0;
int temp=0;
while(cur<=right){
if(nums[cur]==0){
temp=nums[left];
nums[left]=nums[cur];
nums[cur]=temp;
left++;
cur++;
continue;
}
else if(nums[cur]==2){
temp=nums[right];
nums[right]=nums[cur];
nums[cur]=temp;
right--;
continue;
}else
cur++;
}
}
}