Recursion in Python ( beat 50% )


  • 1
    R
    class Solution(object):
        def isUgly(self, num):
            """
            :type num: int
            :rtype: bool
            """
            if num in [1,2,3,5]:
              return(True)
            if not num:
              return(False)
              
            if not (num % 2):
              return(self.isUgly(num/2))
            elif not (num % 3):
              return(self.isUgly(num/3))
            elif not (num % 5):
              return(self.isUgly(num/5))
              
            return(False)
    

Log in to reply
 

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