forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
50 lines (39 loc) · 967 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/// Source : https://leetcode.com/problems/longest-increasing-subsequence/description/
/// Author : liuyubobobo
/// Time : 2017-11-18
#include <iostream>
#include <vector>
using namespace std;
/// Ad-Hoc
/// Time Complexity: O((right-left+1)*log10(right))
/// Space Complexity: O(1)
class Solution {
public:
vector<int> selfDividingNumbers(int left, int right) {
vector<int> res;
for(int i = left ; i <= right ; i ++)
if(selfDividing(i))
res.push_back(i);
return res;
}
private:
bool selfDividing(int num){
int t = num;
while(t){
int x = t % 10;
t /= 10;
if(x == 0 || num % x != 0)
return false;
}
return true;
}
};
void printVec(const vector<int>& vec){
for(int e: vec)
cout << e << " ";
cout << endl;
}
int main() {
printVec(Solution().selfDividingNumbers(1, 22));
return 0;
}