My python solution


  • 0
    Y
    class Solution:
        # @param {integer} n
        # @return {boolean}
        def isHappy(self, n):
            squareresult = [0,1,4,9,16,25,36,49,64,81]
            resultset = set()
            temp = n
            while temp != 1:
                x = 0
                for num in str(temp):
                    x += squareresult[int(num)]
                if x in resultset: return False
                resultset.add(x)
                temp = x
            return True

Log in to reply
 

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