Very concise 0ms C solution


  • 0
    B
    void swap(int *a,int *b){int c = *a; *a=*b; *b=c;}
    void sortColors(int* arr, int numsSize) {
        int i=0,j=0,k=numsSize-1;
        while(j<=k){
            if(arr[j]<1) swap(&arr[i++],&arr[j++]);
            else if(arr[j]>1) swap(&arr[j],&arr[k--]);
            else j++;
        }
    }

Log in to reply
 

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