Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created January 19, 2018 13:44
Show Gist options
  • Save s4553711/a3b5262a409d4cdb66528258d07c5204 to your computer and use it in GitHub Desktop.
Save s4553711/a3b5262a409d4cdb66528258d07c5204 to your computer and use it in GitHub Desktop.
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