My simple c++ solution, just similar to partition()...


  • 0
    L

    It's really similar to the solution of partition:

        void moveZeroes(vector<int>& nums) {                                           
            for(int i=0, z=0; i<nums.size(); i++) {
                if (nums[i] != 0) {
                    swap(nums[i], nums[z++]);
                }
            }
        }
    

Log in to reply
 

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