---恢复内容开始---

题目描述:

第一次提交:

class Solution:
def countAndSay(self, n: int) -> str:
f = ""
for i in range(n-1):
count = 0
c = ''
for j in range(len(f)):
if j == 0 or (j - 1 > -1 and f[j]==f[j-1]):
count += 1
else:
c += str(count) + f[j - 1]
count = 1
c += str(count) + f[j]
i += 1
f = c; return f

方法二:递归

def countAndSay(self, n: int) -> str:
def count(n, str_num):
if n <= 1:
return str_num
new_str_num = ""
cnt, old = 1, str_num[0]
for ch in str_num[1:]:
if ch != old:
new_str_num += str(cnt) + old
cnt, old = 1, ch
else:
cnt += 1
if cnt:
new_str_num += str(cnt) + str_num[-1]
return count(n-1, new_str_num)
return count(n, "")

最新文章

  1. 关于handler 和 looper 的问题
  2. height:100%不起作用(无效),div全屏
  3. SharePoint 2013 开发——搜索架构及扩展
  4. xfce4桌面自动整理脚本
  5. Linux运维命令之一
  6. 关于easyui的一些小知识点(1)
  7. 关于font awesome或Glyphicons字体图标不能正确显示的问题
  8. IOS开发UIImage中stretchableImageWithLeftCapWidth方法的解释
  9. java单元测试(Junit)
  10. jquery选择器 之 获取父级元素、同级元素、子元素 - yes的日志 - 网易博客
  11. api接口json串换行
  12. SpringMVC4+MyBatis+SQL Server2014+druid 监控SQL运行情况
  13. 【SqlServer系列】子查询
  14. 【渗透课程】第三篇-体验http协议的应用
  15. Oracle DBA 常用查询
  16. python 类和元类(metaclass)的理解和简单运用
  17. django之路由层
  18. 【UML】NO.47.EBook.5.UML.1.007-【UML 大战需求分析】- 部署图(Deployment Diagram)
  19. (转)C# Windows服务 弹出消息提醒框
  20. hdu4292 Food 最大流

热门文章

  1. 梯度提升树GBD
  2. python列表中enumerate和zip函数用法
  3. Java 四种内部类
  4. java oop第11章_反射、BaseDao的进一步改造
  5. zdump - 时区输出器
  6. 10_PAE_非PAE
  7. Dubbo中有哪些角色?
  8. zepto-touch事件
  9. leetcood学习笔记-226- 翻转二叉树
  10. Batch - %~dp0 vs %cd%