C solution 1loop O(1)Space O(n)Time No swap


  • 0
    Z

    void moveZeroes(int* nums, int numsSize) {
    int i,count;
    i = 0, count = 0;
    for(; i < numsSize; i++) {
    if(nums[i] == 0) {
    count++;
    } else {
    if(nums[i - count] != nums[i]) {
    nums[i - count] = nums[i];
    nums[i] = 0;
    }
    }
    }
    }


Log in to reply
 

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