Python Recursive Solution


  • 0
    Q
    def isHappy(self, n):
        """
        :type n: int
        :rtype: bool
        """
        res = sum([int(x) ** 2 for x in str(n)])
        if res == 1 or res == 7:
            return True
        elif res <10:
            return False
        else:
            return self.isHappy(res)

Log in to reply
 

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