Move Zeros

code


class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        if(nums.size() == 0)
        {
            return ;
        }

        for(int i = 0; i<nums.size(); i++)
        {
            if(nums[i] != 0)
            {
                continue;
            }

            for(int j = i+1; j<nums.size(); j++)
            {
                if(nums[j] != 0)
                {
                    int tmp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = tmp;
                    break;
                }
            }
        }
    }
};

results matching ""

    No results matching ""