O(n) c++ less than 10 lines


  • 0
    T

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


Log in to reply
 

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