技术栈

Python | Leetcode Python题解之第38题外观数列

Mopes__2024-04-20 18:31

题目:

题解:

python 复制代码
class Solution:
    def countAndSay(self, n: int) -> str:
        prev = "1"
        for i in range(n-1):
            curr = ""
            pos = 0
            start = 0

            while pos < len(prev):
                while pos < len(prev) and prev[pos] == prev[start]:
                    pos += 1
                curr += str(pos - start) + prev[start]
                start = pos
            prev = curr
        
        return prev
上一篇:Webrtc 信令服务器实现
下一篇:2024.4.16 Python爬虫复习day04
相关推荐
ZhengEnCi
1 天前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风
1 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风
1 天前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
Flittly
2 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent
千寻girling
2 天前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook
2 天前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风
2 天前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风
2 天前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei
3 天前
python 抽象基类
python
用户835629078051
3 天前
Python 实现 PPT 转 HTML
后端·python
热门推荐
01GitHub 镜像站点02OpenClaw 使用和管理 MCP 完全指南03OpenClaw 连接飞书完整指南:插件安装、配置与踩坑记录04Window 10部署openclaw报错node.exe : npm error code 12805本地部署 OpenClaw + DeepSeek-R1 完全指南06OpenClaw + 飞书(Feishu)环境搭建指南07npm-error code 128问题解决方法08Clawdbot部署教程:解决‘gateway token missing’授权问题的完整步骤09OpenClaw 飞书机器人不回复消息?3 小时踩坑总结10Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services