728x90
반응형
Solution
- Calculate digit, Check integer is divable by all digits
class Solution {
public:
bool IdSelfDividingNumber(int n)
{
int k = 10;
int a = n;
for (int i = 1; i != 5; ++i)
{
int digit = a % k;
if (digit == 0)
{
return false;
}
else if (n % digit != 0)
{
return false;
}
else
{
// Do Nothing
}
a = a / k;
if (a == 0)
{
return true;
}
}
return true;
}
vector<int> selfDividingNumbers(int left, int right) {
vector<int> res;
for (int i = left; i < (right + 1); ++i)
{
if (IdSelfDividingNumber(i) == true)
{
res.push_back(i);
}
else
{
// DO Nothing
}
}
return res;
}
};
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[LeetCode] 771, Jewels and Stones (0) | 2023.02.14 |
---|---|
[LeetCode] 1720 Decode XORred Array (0) | 2023.01.29 |
[LeetCode] 2032. Two Out of Three, C++ (0) | 2023.01.25 |
[Leet Code] 231. Power of Two, C++ (0) | 2023.01.17 |
[LeetCode] 2331. Evaluate Boolean Binary Tree, cpp (0) | 2023.01.10 |