simple and quick python solution

  • 0
    # 202 Happy Number
    class Solution(object):
        def isHappy(self, n):
            :type n: int
            :rtype: bool
            temp = set()
            while True:
                digit = map(int, str(n))
                summ = sum([i*i for i in digit])
                if summ == 1: return True
                elif summ in temp: return False
                else: temp.add(summ)
                n = summ

Log in to reply

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