class Solution:
# @param {int} num an integer
# @return {boolean} true if num is an ugly number or false
def isUgly(self, num):
# Write your code here
if num == 0:
return False
while num != 2 or num != 3 or num != 5:
if num % 2 == 0:
num /= 2
elif num % 3 == 0:
num /= 3
elif num %5 == 0:
num /= 5
else:
break
if num == 1:
return True
return False
LintCode:Ugly Number
最新推荐文章于 2022-11-18 10:09:03 发布