Ugly number python solution


  • 0

    class Solution(object):
    def isUgly(self, num):
    """
    :type num: int
    :rtype: bool
    """
    if num <= 0:
    return False

        while True:
            if num%2 == 0:
                num = num/2
            elif num%3 == 0:
                num = num/3
            elif num%5 == 0:
                num = num/5
            else:
                return num == 1
    

    test = Solution()
    print test.isUgly(3030)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.