llllmz

导航

283. 移动零c

void moveZeroes(int* nums, int numsSize) {
    int head=0,tail=0;
    while(tail<numsSize){
        if(nums[tail]!=0){
            nums[head++]=nums[tail++];
        }else{
            tail++;
        }
    }
    for(;head<numsSize;head++){
        nums[head]=0;
    }
}

双指针,要注意移完后还有置零。

posted on 2024-03-12 15:03  神奇的萝卜丝  阅读(18)  评论(0)    收藏  举报