题解:
要判断一个整数n是否为丑数,可以通过不断地将n除以2、3和5,直到无法再除为止。如果最终得到的结果是1,那么n就是丑数;否则,n不是丑数。
class Solution:
def isUgly(self, n: int) -> bool:
if n <= 0:
return False
while n % 2 == 0:
n //= 2
while n % 3 == 0:
n //= 3
while n % 5 == 0:
n //= 5
return n == 1