Accepted C/c++ solution


  • -1
    R
    class Solution {
    public:
        void moveZeroes(vector<int>& nums) {
            
            for(int i=0; i<nums.size(); i++) {
                if(nums[i] == 0) {
                    int j = i + 1;
                    while((nums[j] == 0) && (j < nums.size())) {
                        j++;
                    }
                    
                    if(j >= nums.size()) {
                        printf("\n no more trailing numbers ");
                        break;
                    } else {
                        swap(nums[i], nums[j]);
                    }
                }
            }
        }
    };

Log in to reply
 

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