【leetcode】1317. 将整数转换为两个无零整数的和

 

int* getNoZeroIntegers(int n, int* returnSize){
    int unit, i, num=0, cnt=0, temp=n;
    int* arr=(int*)calloc(2,sizeof(int));
    while(n>0){
        unit=n%10;
        for(i=1; i<=9 && i<=n; i++){
            if (unit-i != 0)
            {
                num+=i*pow(10,cnt);
                break;
            }
        }
        n/=10;
        if(unit<i) 
            n-=1;
        cnt++;
    }
    *returnSize=2;
    arr[0]=num, arr[1]=temp-num;
    return arr;
}

 

posted @ 2020-11-25 17:49  温暖了寂寞  阅读(102)  评论(0编辑  收藏  举报