My accepted C solution, easy to understand


  • -1
    W
    void moveZeroes(int* nums, int numsSize) {
    int i,j,count = 0,IsNotZero = 0;
    for( i = 0; i < numsSize; i++ )
    {
        if(nums[i]!=0)
        IsNotZero++;``
    }
    for( i = 0; i< numsSize;  )
    {
        if(count == IsNotZero)
        break;
        if( 0 == nums[i] )
        {
            for( j = i;j < numsSize; j++ )  //move zero
            {
                nums[j] = nums[j+1];
            }
            nums[numsSize-1] = 0;
        }
        else
        {
         count++; i++;  
        }
    }
    

    }


  • 0
    C
    This post is deleted!

Log in to reply
 

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