题目链接
https://leetcode.com/problems/count-and-say/
题目原文
The count-and-say sequence is the sequence of integers beginning as follows:
1, 11, 21, 1211, 111221, ...
1
is read off as"one 1"
or11
.
11
is read off as"two 1s"
or21
.
21
is read off as"one 2, then one 1"
or1211
.
Given an integer n, generate the nth sequence.Note: The sequence of integers will be represented as a string.
题目翻译
一个”数和说(count and say)“序列是像这样的一个整数序列:1, 11, 21, 1211, 111221, ...
。
1
读作 "1个1"
或 11
.
11
读作 "2个1"
或 21
.
21
读作 "1个2,1个1"
或 1211
.
给定整数n,生成第n个序列。
注意:整数序列用字符串表示。
思路方法
这个问题重点首先是要读懂题目。然后在想这个过程的时候,你可能会想的比较复杂,比如,会不会出现连续十几个一样的数字,比如1111111111,读作“ten 1”,然后转换成101。实际上,有大神已经证明,这个序列里的数不会超过4。这边搬运了一下。
原链接:https://leetcode.com/discuss/6762/how-to-proof-the-count-is-always-less-than-10
Proof by exhaustion and contrapositive:
In order for a number greater than 4 to be created, there must be a series of numbers n>4 in length all the same digit. Therefore, there is a subset of th