Simple Python Solution


  • 0
    M
    class Solution(object):
        def isHappy(self, n):
            """
            :type n: int
            :rtype: bool
            """
            seen = set()
            n_str = str(n)
            while n != 1:
                n = sum(map(lambda x: int(x)**2, n_str))
                n_str = str(n)
                if n in seen:
                    return False
                else:
                    seen.add(n)
            return True
    

Log in to reply
 

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