> For the complete documentation index, see [llms.txt](https://r24zeng.gitbook.io/leetcode-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r24zeng.gitbook.io/leetcode-notebook/zhong-yu-shua-dao-100-dao-le-wo-shi-fen-shui-ling/bu-chong-120-dao/38.-count-and-say.md).

# 38. Count and Say

\# Easy

{% hint style="info" %}
recursive, 理解题意最难，根据上一个的结果去做下一次的迭代
{% endhint %}

{% tabs %}
{% tab title="Python" %}

```python
class Solution:
    def countAndSay(self, n: int) -> str:
        result = '1'
        while n > 1:
            s = result
            result = ''
            i = 0
            while i < len(s):
                value = s[i]
                count = 0
                while i < len(s) and s[i] == value:
                    count += 1
                    i += 1
                result += str(count) + str(value)
            n -= 1
        return result
```

{% endtab %}
{% endtabs %}
