C++ solution - small and simple


  • 0
    G
    class Solution {
    public:
        void moveZeroes(vector<int>& nums) {
            
            int run = nums.size() - 1;
            int count = 0;
            while(run >= 0){
                
                if(nums[run] != 0){
                    run--;
                    count++;
                    continue;
                }
                
                reverse(nums.begin() + run, nums.begin() + run + count + 1);
                reverse(nums.begin() + run,nums.begin() + run + count);
                run--;
            }
        }
    };
    

Log in to reply
 

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