就很蠢的办法
class Solution(object):
def isUgly(self, num):
"""
:type num: int
:rtype: bool
"""
if num <= 0:
return False
while num > 1:
if num % 30 == 0:
num = num / 30
elif num % 15 == 0:
num = num / 15
elif num % 10 == 0:
num = num / 10
elif num % 6 == 0:
num = num / 6
elif num % 2 == 0:
num = num / 2
elif num % 3 == 0:
num = num / 3
elif num % 5 == 0:
num = num / 5
else:
return False
return True
网友评论