leetcode解题方案--038--count and say
2017-11-21 16:35
309 查看
题目
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(); } }
相关文章推荐
- LeetCode 038 Count and Say
- LeetCode 038 Count and Say
- LeetCode038 Count and Say
- leetcode 038 —— Count and Say
- [LeetCode]038-Count And Say
- Java for LeetCode 038 Count and Say
- LeetCode 038-Count and Say
- leetcode 038 Count and Say
- LeetCode解题报告-- Count and Say
- leetcode之路038 Count and Say
- 【LeetCode】Count and Say 解题报告
- LeetCode: Count and Say 解题报告
- leetcode 038 Count and Say
- LeetCode 038 Count and Say
- 【LeetCode-面试算法经典-Java实现】【038-Count and Say(计数和表述)】
- [LeetCode]题解(python):038-Count and Say
- leetcode 038 Count and Say
- leetcode_c++:Count and Say(038)
- int转string与LeetCode:Count and Say
- leetcode解题方案--074--Search a 2D Matrix