Java solution with 2 pointers


  • 0
    T
        int length = nums.length;
        int j = 0;
        for (int i = 0; i < length; i++) {
            if (nums[i] != 0) {
                nums[j] = nums[i];
                j += 1;
            }
        }
        for (int k = j; k < length; k++) {
            nums[k] = 0;
        }

Log in to reply
 

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