Python iterative solution.


  • 0
    C
    def isHappy(self, n):
        dic = {}
        while n:
            if 1 in dic:
                return True
            if n in dic:
                return False
            dic[n] = 0
            tmp = 0
            while n:
                tmp += (n%10)**2
                n //= 10
            n = tmp

Log in to reply
 

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