# 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)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://r24zeng.gitbook.io/leetcode-notebook/bu-chong-6180-dao/202.-happy-number.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
