Created
January 19, 2018 13:44
-
-
Save s4553711/a3b5262a409d4cdb66528258d07c5204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> selfDividingNumbers(int left, int right) { | |
vector<int> res; | |
for(int i = left; i <= right; i++) { | |
int t = i; | |
bool val = true; | |
while(t && val) { | |
const int r = t % 10; | |
//cout << "r: " << r << ", i:" << i << ", i%r" << i%r << endl; | |
if (r == 0 || i % r) val = false; | |
t /= 10; | |
} | |
if (val) res.push_back(i); | |
} | |
return res; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment