My python solution


  • 0
    A
    def isHappy(self, n):
        """
        :type n: int
        :rtype: bool
        """
        s = list(str(n))
        result = 0
        if n == 4:
            return False
        elif n == 1:
            return True
        else:
            for i in s:
                result += int(i) ** 2
            return self.isHappy(result)

Log in to reply
 

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