【leetcode】复写零

 

void duplicateZeros(int* arr, int arrSize){
    int* ans = (int*)calloc(arrSize+1,sizeof(int));
    int i,pst=0;
    for(i=0; i<arrSize && pst<arrSize; i++){
        ans[pst++]=arr[i];
        if(arr[i]==0){
            ans[pst++]=arr[i];
        }
    }
    for(i=0; i<arrSize; i++)
        arr[i]=ans[i];
}

 

posted @ 2020-11-19 09:55  温暖了寂寞  阅读(61)  评论(0编辑  收藏  举报