---
description: '# Easy'
---

# 202. Happy Number

{% hint style="info" %}
Key idea:

If sumNumbers=1, this number is happy number.

If sumNumbers has showed up before, then it will go to endless cycle, it is not a happy number.
{% endhint %}

```
class Solution:
    def isHappy(self, n: int) -> bool:
        if n == 1:
            return True
        
        numbers = set()
        while n != 1:
            if n in numbers:
                return False
            numbers.add(n)
            n = self.sumNumber(n)

        return True
    
    def sumNumber(self, n):
        if n//10 == 0:
            return n*n
        
        return (n%10)*(n%10) + self.sumNumber(n//10)
```

