C++ 13ms beats:90%


  • 1
    H

    class Solution {
    public:
    void moveZeroes(vector<int>& nums) {
    //swap all the nonzero with zero
    for (register int i = 0,j=0; i < nums.size(); ++i) {
    if (nums[i] != 0) {
    swap(nums[j++], nums[i]);
    }
    }

    }
    

    };


Log in to reply
 

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