C++ 3 lines


  • 0
    B
    class Solution {
    public:
        void moveZeroes(vector<int>& nums) {
            int index = 0;
            for(auto e : nums) if(e) nums[ index++ ] = e;
            while(index < nums.size()) nums[ index++ ] = 0;
        }
    };

Log in to reply
 

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