Leetcode 283 Solution

This article provides solution to leetcode question 283 (move-zeroes)

https://leetcode.com/problems/move-zeroes

Solution

class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int l = 0;
        int r = 0;

        while (r < nums.size())
        {
            if (nums[r] == 0)
                r++;
            else
                swap(nums[l++], nums[r++]);
        }
    }
};