Two lines C++ Accepted


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

  • 0
    T

    This performs unnecessary writes if the array contains all nonzeroes on the left to begin with.


Log in to reply
 

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