【leetcode】自除数

 

bool func(int x){
    int temp = x;
    while(temp){
        if(temp % 10 && x % (temp % 10) == 0) temp /= 10;
        else return false;
    }
    return true;
}
int* selfDividingNumbers(int left, int right, int* returnSize){
    int* arr = (int*)calloc(right-left,sizeof(int));
    int n=0;
    for (int i=left; i<=right; i++)if (func(i)) arr[n++] = i;        
    *returnSize = n;
    return arr;
}

 

posted @ 2020-09-06 15:20  温暖了寂寞  阅读(130)  评论(0编辑  收藏  举报