My Python Solution


  • 0
    D
    class Solution:
    # @param {integer} n
    # @return {boolean}
    def isHappy(self, n):
        count = []
        while (True): 
            total = 0 
            count.append(str(n))
            for i in str(n):
                total += int(i) ** 2
            n = str(total)
        if n == "1":
            return "True"
            break
        if n in count:
            return "False"
            break

  • 2
    M

    'break' may not be necessary, and the quotation marks of True and False can be dropped ^ ^


Log in to reply
 

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