8ms C code with pointer


  • 0
    1

    but only 37% beat rate, why?

    void moveZeroes(int* nums, int numsSize) {
        int *p = nums;
        int *p_end = nums + numsSize;
        for (int *p2 = nums; p2<p_end; ++p2) {
            if (*p2 != 0) {
                *p++ = *p2;
            }
        }
        for (; p<p_end; ++p) {
            *p = 0;
        }
    }

Log in to reply
 

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