Fb6ac2e4fa0a0aefdd44d55863972033
(难度坑爹)Problem 38. Count and Say (数数和计数)

链接

https://leetcode.com/problems/count-and-say/

难度等级

Easy

题干

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

1.     1
2.     11
3.     21
4.     1211
5.     111221
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.

题意

这题绝壁不是easy难度,光题意我觉得就算得上hard。。。

给定一个数n,要求返回一个字符串。

坑爹的地方来了,这个字符串怎么来的呢?

这个字符串有一个神奇的计算方法叫做count-and-say,言下之意,就是一边计数一边存。比如11,英文里叫two one,意思是两个1,所以记录成21。

21呢又读作one two one one,意思是一个2一个1,所以记成1211.

我们要返回的正是第n个字符串。

那么问题来了,我们怎么知道第n个字符串是什么呢?

答案是第n个字符串是由第n-1个字符串通过上述的操作得到的。

样例

```
Example 1:

Input: 1

top Created with Sketch.