美文网首页
263. Ugly Number

263. Ugly Number

作者: April63 | 来源:发表于2018-06-24 19:49 被阅读0次

就很蠢的办法

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

相关文章

网友评论

      本文标题:263. Ugly Number

      本文链接:https://www.haomeiwen.com/subject/xxikyftx.html