Fast and simple Python Solution(using hash)

  • 2
    class Solution(object):
    def isHappy(self, n):
        dic = {}
        while (n!=1):
            if n in dic:
                return False
            dic[n] = 1
            total = 0
                total = total + (n%10)*(n%10)
                n = n/10
            n = total
        return True

Log in to reply

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