C++ 16ms Simple Solution(erase)


  • 0
    G

    class Solution {
    public:
    void moveZeroes(vector<int>& nums) {
    int imax = nums.size();
    for (int i=1; i<=imax; i++){
    if (nums[i-1]==0){
    nums.erase(nums.begin()+i-1);
    nums.push_back(0);
    imax = imax-1;
    i--;
    }
    }
    }
    };


Log in to reply
 

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