Poison

263. Ugly Number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public boolean isUgly(int n) {
if (n <= 0) {
return false;
}

while (n % 5 == 0) {
n /= 5;
}
while (n % 3 == 0) {
n /= 3;
}
while (n % 2 == 0) {
n /= 2;
}

return n == 1;
}
}
Reference

263. Ugly Number