leetcode解题方案--038--count and say
来源:互联网 发布:java写的桌面程序 编辑:程序博客网 时间:2024/05/22 12:03
题目
The count-and-say sequence is the sequence of integers with the first five terms as following:
- 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.
后一个字符串是前一个字符串的读法
public static String countAndSay(int n) { if (n<1) { return ""; } if (n==1) { return "1"; }else { char[] str = countAndSay(n-1).toCharArray(); int count = 1; char curr = ' '; StringBuffer xx = new StringBuffer(""); for (int i = 0;i<str.length;i++) { if (str[i]!=curr) { if (curr!=' ') { xx.append(count); xx.append(curr); } count = 1; curr = str[i]; } else { count++; } } xx.append(count); xx.append(curr); return xx.toString(); } }
阅读全文
0 0
- leetcode解题方案--038--count and say
- LeetCode Count and Say 解题报告
- LeetCode解题报告-- Count and Say
- [leetcode] 38. Count and Say 解题报告
- [Leetcode] 38. Count and Say 解题报告
- 【LeetCode】Count and Say 解题报告
- count and say 解题
- LeetCode 038 Count and Say
- LeetCode 038-Count and Say
- leetcode 038 Count and Say
- LeetCode 038 Count and Say
- LeetCode 038 Count and Say
- [LeetCode]038-Count And Say
- leetcode 038 Count and Say
- leetcode 038 Count and Say
- LeetCode 038 Count and Say
- LeetCode: Count and Say
- [LeetCode]Count and Say
- 《hbase学习》-07-HBase 更改表名
- JAVA8新特性总结一(接口函数默认实现)
- webpack3+react16+react-router3+react-redux实战项目
- tomcat安装中遇到的莫名奇妙的问题
- 探索Android软键盘的疑难杂症
- leetcode解题方案--038--count and say
- RegExp类型
- 刷LeetCode(12)——Integer to Roman
- Android心跳包(一)——心跳实现
- 二叉树的按层打印与ZigZag打印
- 11.21 仙人掌专题
- Qt笔记_调试qDebug
- 基础练习 矩阵乘法
- 【LeetCode】258. Add Digits