38. Count and Say

来源:互联网 发布:ipad监控软件 编辑:程序博客网 时间:2024/05/01 21:13

题目摘要
报数指的是,按照其中的整数的顺序进行报数,然后得到下一个数。如下所示:
1, 11, 21, 1211, 111221, ...
给定一个整数 n, 返回 第 n 个序列。
解法
从n = 1开始(while (--n > 0)),新建一个StringBuilder,用双指针法遍历该字符串,往sb里添加字符

注意

原题

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" 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, generate the nth sequence.

0 0
原创粉丝点击