Solution
Definition
Complexity
time: O(logn)
space: O(1)
def isUgly(self, n: int) -> bool:
prime_factors = [2, 3, 5]
temp = n
while temp != 1:
for pf in prime_factors:
if temp % pf == 0:
temp = temp // pf
if temp == n:
return False
n = temp
return True
1
2
3
4
5
6
7
8
9
10
11