my python solution


  • 1
    S
    class Solution(object):
        def isHappy(self, n):
            """
            :type n: int
            :rtype: bool
            """
            col = set()
            while(n not in col):
                col.add(n)
                n = sum(int(i)**2 for i in str(n))
            return n==1
    

  • 0
    R

    interesting. I wonder , what will be the algorithmic complexity of this solution.


Log in to reply
 

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