LeetCode—728. Self Dividing Numbers


//url:https://leetcode.com/problems/self-dividing-numbers/description/



class Solution {
public:
    vector selfDividingNumbers(int left, int right) {
        vector result;
        for(int i=left;i<=right;i++){
            int n=i;
            bool isDividingNum=true;
            while(n){
                if(0==n%10||0!=(i%(n%10))){
                    isDividingNum=false;
                    break;
                }
                n/=10;
            }
            if(isDividingNum)
                result.push_back(i);
        }
        return result;
    }
};


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注