[LeetCode]263. Ugly Number
题目描述
思路
按照题目要求暴力计算
代码
#include <iostream>
using namespace std;
class Solution {
public:
bool isUgly(int num) {
if (num == 0)
return false;
if (num == 1)
return true;
while (num % 2 == 0)
num /= 2;
while (num % 3 == 0)
num /= 3;
while (num % 5 == 0)
num /= 5;
return num == 1;
}
};
int main() {
Solution s;
cout << s.isUgly(7) << endl;
system("pause");
return 0;
}