My python solution

  • 0
    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
                temp = x
            return True

Log in to reply

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