0ms C解决方案


  • 0
    L
    void sortColors(int* nums, int numsSize) {
        int x1=0,x2=0,x3=0,i;
        for(i=0;i<numsSize;i++)
        {
            if(nums[i]==0)
            x1++;
            else if(nums[i]==1)
            x2++;
            else if(nums[i]==2)
            x3++;
        }
        i=0;
        while(x1)
        {
            nums[i++]=0;
            x1--;
        }
        while(x2)
        {
            nums[i++]=1;
            x2--;
        }
        while(x3)
        {
            nums[i++]=2;
            x3--;
        }
        return nums;
        
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.