Leetcode 263 Solution
This article provides solution to leetcode question 263 (ugly-number)
Access this page by simply typing in "lcs 263" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/ugly-number
Solution
class Solution {
public:
bool isUgly(int num) {
if (num <= 0)
return false;
while (num != 1)
{
if (num % 2 == 0)
num /= 2;
else if (num % 3 == 0)
num /= 3;
else if (num % 5 == 0)
num /= 5;
else
return false;
}
return true;
}
};