LintCode:Ugly Number

LintCode:Ugly Number

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)