Very simple Python solution


  • 0
    T

    Pretty simple solution in python. A little dirty having that count to check if it is looping too much but my solution was accepted.

    class Solution(object):
        def isHappy(self, n):
            """
            :type n: int
            :rtype: bool
            """
            count = 0
            if not n:
                return False
            while(n != 1):
                count +=1
                n = sum([int(digit)**2 for digit in str(n)])
                if count>500: 
                    return False
            return True
    

Log in to reply
 

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