python solution


  • 0
    X
    class Solution(object):
        def isHappy(self, n):
            """
            :type n: int
            :rtype: bool
            """
            c = 0
            while n>1:
                s = str(n)
                n = 0
                c += 1
                for i in range(len(s)):
                    n += int(s[i])*int(s[i])
                if c>100:
                    return False
                    break
                else:
                    continue
            if n==1:
                return True
    

Log in to reply
 

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