17 lines
332 B
Python
17 lines
332 B
Python
# Ugly number
|
|
# If positive number n has prime factors limited to 2, 3 and 5,
|
|
# it's a ugly prime
|
|
# -2^31 <= n <= 2^31 - 1
|
|
|
|
|
|
class Solution:
|
|
def isUgly(self, n: int) -> bool:
|
|
if n <= 0:
|
|
return False
|
|
|
|
for p in [2, 3, 5]:
|
|
while n % p == 0:
|
|
n = n // p
|
|
|
|
return n == 1
|