leetcode - 75. Sort Colors

在这里插入图片描述

class Solution {
public:
    void sortColors(vector<int>& nums) {
        int p[3]={};
        for(auto it:nums)
        {
            ++p[it];
        }
        int i=0;
        for(int j=0;j<3;++j)
        {
            for(;p[j];--p[j],++i)
            {
                nums[i]=j;
            }
        }
        return ;
    }
};

猜你喜欢

转载自blog.csdn.net/weixin_41938758/article/details/89075778