LC 75. Sort Colors

Link

class Solution {
public:
    void sortColors(vector<int>& nums) {
        int low=0;
        int high=nums.size()-1;
        for(int i=0;i<=high;){
            if(nums[i]==0){
                swap(nums[i++],nums[low++]);
            }else if(nums[i]==2){
                swap(nums[i],nums[high--]);
            }else i++;
        }
    }
};
posted @ 2020-06-12 07:51  feibilun  阅读(53)  评论(0编辑  收藏  举报