Leetcode题库 728.自除数(C实现)
生活随笔
收集整理的這篇文章主要介紹了
Leetcode题库 728.自除数(C实现)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 思路
- 代碼
思路
1、func函數:
獲取n的每一位數
若該數不為0, 則驗證n是否整除該數
代碼
bool func(int n){int t_0=n,t_1=t_0%10;bool ret=true;do{if(t_1!=0 && n%t_1==0){t_0=(t_0-t_1)/10;t_1=t_0%10;}else{ret=false;break;}}while(t_0>0);return ret; }int* selfDividingNumbers(int left, int right, int* returnSize){int l=right-left+1,*ret=(int*)malloc(sizeof(int)*l);*returnSize=-1;for(int i=0;i<l;i++){if(func(i+left)) ret[++(*returnSize)]=i+left;}(*returnSize)++;return ret; } 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Leetcode题库 728.自除数(C实现)的全部內容,希望文章能夠幫你解決所遇到的問題。