Two pointers C++


  • 0
    J
    class Solution {
    public:
        void moveZeroes(vector<int>& nums) {
            int zero = 0, walk = 0, N = nums.size();
            while (walk < N) {
                if (nums[walk++] != 0) 
                    swap(nums[zero++], nums[walk - 1]);
            }
        }
    };

Log in to reply
 

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