Simple C Solution, 8ms


  • 3
    P
    void moveZeroes(int* nums, int numsSize) {
        int runnerIndex = 0;
        int chaserIndex = 0;
        
        for(runnerIndex = 0; runnerIndex < numsSize; runnerIndex++) {
            if(nums[runnerIndex] != 0){
                if(runnerIndex != chaserIndex) {
                    nums[chaserIndex] = nums[runnerIndex];
                    nums[runnerIndex] = 0;
                }
                chaserIndex++;
            }
        }
    }

  • 0
    P

    Nice solution man!


  • 0
    P
    This post is deleted!

Log in to reply
 

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