C++ solution easy to understand beat run time beats 96%


  • 0
    Z
    class Solution {
    public:
        void moveZeroes(vector<int>& nums) {
            
            int i= 0;
            int count=0;
            
         while(i<nums.size())
         {
            if(nums[i]!=0)
            {
              swap(nums[count],nums[i]);
              count++;
              i++;
            }
            else i++;
         }  
            
        }
    };
    

Log in to reply
 

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