My python solution:

  • 0
    def isHappy(self, n):
        :type n: int
        :rtype: bool
        if n == 1:
            return True
        seen = set()        
        while n not in seen:
            n = self.calculate(n)
        if n == 1:
            return True
            return False
    def calculate(self, num):
        ret = 0
        while num:
            ret += (num%10)**2
            num = num//10
        return ret

Log in to reply

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