思想:先判断num是不是负数,若是则返回False。若不是则进入while循环。若是丑数,经过不断除2或者除3或者5,最终商一定为1,反之则不是。
class Solution:
def isUgly(self, num):
"""
:type num: int
:rtype: bool
"""
if num<=0:
return False
while num > 1:
if 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
哈哈哈哈哈,小菜鸟的思想和大佬的不谋而合,有潜力的小菜鸟