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.
Note: The sequence of integers will be represented as a string.
这个题目理解起来真是太难了,尤其是英文又不好,只能参看下别人的资料,理解下规则。终于理解,题意是n=1时输出字符串1;n=2时,数上次字符串中的数值个数,因为上次字符串有1个1,所以输出11;n=3时,由于上次字符是11,有2个1,所以输出21;n=4时,由于上次字符串是21,有1个2和1个1,所以输出1211。依次类推,写个countAndSay(n)函数返回字符串。
public String countAndSay(int n) {
if (n == 1

本文介绍了LeetCode中第38题——数说序列的生成。该序列从1开始,如1, 11, 21, 1211, 111221等。题目要求根据给定的整数n生成对应的序列字符串。理解题意的关键在于,每个数是根据前一数中各数字出现的次数来描述的。递归和非递归两种解法被讨论,其中非递归解法使用了双层循环来实现。"
123303688,10438249,使用OpenXml高效导出.NET大数据到Excel,"['.NET开发', '数据导出', 'OpenXML', 'Excel处理']
订阅专栏 解锁全文
300

被折叠的 条评论
为什么被折叠?



