clueless coding // TODO: be smarter

LeetCode Move Zeroes: CPP Solution



TL;DR Code Solution


void moveZeroes(vector<int>& nums) {

    int insert = 0;
    for (int i = 0; i < nums.size(); i++) {
        if (nums[i] != 0) {
            nums[insert++] = nums[i];
        }
    }

    for (int i = insert; i < nums.size(); i++) {
        nums[i] = 0;
    }

}