Python, 60ms, Long Solution


  • 0
    X

    class Solution:

    def isMod(self, k, num):
        if num % k == 0: return True
        else: return False
    def isUgly(self, num):
        """
        :type num: int
        :rtype: bool
        """
       
        if num == 1: return True
        elif num <= 0: return False
        else:
            while num > 0:
                if self.isMod(2,num): num = num / 2; continue
                if self.isMod(3,num): num = num / 3; continue
                if self.isMod(5,num): num = num / 5; continue
            
                if num > 1: return False
                else: return True

Log in to reply
 

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