C++ solution easy


  • 0
    class Solution {
    public:
        void moveZeroes(vector<int>& nums)
        {
            if(nums.size() == 1 || nums.size() == 0)
                return;
            int temp,i, j;
            for(i = 1; i < nums.size(); i++)
            {
                if(nums[i])
                {
                    temp =nums[i];
                    for(j = i; j > 0 && nums[j-1] == 0; j--)
                        nums[j] = nums[j-1];
                    nums[j] = temp;
                }
            }
        }
    };

Log in to reply
 

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