A pythonic solution

  • 0
    class Solution(object):
    def isHappy(self, n):
        :type n: int
        :rtype: bool
        visited = set()
        while n!=1:
            if n in visited:
                return False
            n = reduce(lambda x,y:x+y,(map(lambda x:int(x)**2,list(str(n)))))
        return True

Log in to reply

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