Happy Number

Problem Id: 202 Difficulty: Easy


Intuition

Happy Number

Solution


class Solution:
    def isHappy(self, n):
        """
        :type n: int
        :rtype: bool
        """
        met_before = set()
        while n != 1:
            n = sum(int(i)*int(i) for i in str(n))
            if n in met_before:
                return False
            met_before.add(n)
        return True