My Python Solution

  • 0
    class Solution:
        # @param {integer} n
        # @return {boolean}
        def isHappy(self, n):
            def calc(num):
                sum_num = 0
                num = str(num)
                for i in num:
                    sum_num = int(i) * int(i) + sum_num
                return sum_num
            l = []
            res = None
            while True:
                n = calc(n)
                if n in l:
                    return False
                elif n == 1:
                    return True

Log in to reply

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