欢迎来我Python萌新的小站

[LEEDCode][038][简单] – 报数(count-and-say)

The count-and-say sequence is the sequence of integers with the first five terms as following:

1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.

Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence.

Note: Each term of the sequence of integers will be represented as a string.

报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数。其前五项如下:

1 被读作  "one 1"  ("一个一") , 即 11
11 被读作 "two 1s" ("两个一"), 即 21
21 被读作 "one 2",  “one 1" ("一个二" ,  "一个一") , 即 1211

给定一个正整数 n(1 ≤ n ≤ 30),输出报数序列的第 n 项。

注意:整数顺序将表示为一个字符串。

示例 1:

示例 2:

解答

验证

提交时间 状态 执行用时 语言
几秒前 通过 48 ms python3

输出结果

 

喜欢 (0)分享 (0)
发表我的评论
取消评论
友情提示:插入代码时请使用:  <pre>要插入的代码</pre>   以达到最佳效果!

表情     9 + 6 = ? (必填)

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址