Accepted C++ 60ms

  • 0
    void moveZeroes(vector<int>& nums) {
        int length = nums.size();
        for(int i = 0; i < length; ++i){
            if(nums[i] == 0){
                for(int j = i; j < length; ++j){
                    nums[j] = nums[j + 1];
            nums[length - 1] = 0;

    Shorten the length of array while moving a zero to the end of the array.

    I was wondering whether my code has applied two pointer method? Thanks!

    I do not think it is a great method by costing 60ms, even though it can be accepted by the OJ. Just for sharing. lol....

Log in to reply

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