LeetCode:728. 自除数

    技术2022-07-11  165

    class Solution { public: bool isSelfDivided(int i) { int temp=i; while(i) { if(temp%(i%10)!=0) { return false; } i/=10; } return true; } bool isContainsZero(int i) { string s=to_string(i); for(int i=0;i<s.size();i++) { if(s[i]=='0') { return true; } } return false; } vector<int> selfDividingNumbers(int left, int right) { vector<int>res; for(int i=left;i<=right;i++) { if(!isContainsZero(i)&&isSelfDivided(i)) { res.push_back(i); } } return res; } };
    Processed: 0.010, SQL: 9