Count and Say LeetCode:Mysolution
来源:互联网 发布:数据标注是什么 编辑:程序博客网 时间:2024/06/04 23:37
Count and Say
Total Accepted: 17238 Total Submissions: 62821My SubmissionsThe 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.\
public class Solution { public String countAndSay(int n) { if (n <= 0) { return ""; } return countSubString(n); } String countSubString(int n) { if (n == 1) { String s = "1"; return s; } String thisN = countSubString(n - 1); char temp = thisN.charAt(0); int count = 0; StringBuffer levelRes = new StringBuffer(); for (int i = 0; i < thisN.length(); i++) { if (temp == thisN.charAt(i)) { count++; } else { levelRes.append(count); levelRes.append(temp); temp = thisN.charAt(i); count = 1; } } levelRes.append(count); levelRes.append(temp); return levelRes.toString(); }}
0 0
- Count and Say LeetCode:Mysolution
- LeetCode: Count and Say
- [LeetCode]Count and Say
- LeetCode Count and Say
- [Leetcode] Count and Say
- Leetcode: Count and Say
- [LeetCode] Count and Say
- LeetCode Count and Say
- [LeetCode]Count and Say
- [LeetCode] Count and Say
- LeetCode-Count and Say
- LeetCode: Count and Say
- LeetCode - Count and Say
- [LeetCode] Count and Say
- Count and Say 【leetcode】
- [LeetCode] Count and Say
- Leetcode Count and Say
- LeetCode Count and Say
- Handler详解系列(一)——Handler异步消息机制详解(附图)
- 学到老活到老
- 关于正则表达式——元字符
- 做java开发这一年
- 【Linux】【CGI】cgic: CGI的C函数库
- Count and Say LeetCode:Mysolution
- [Leetcode] Add Binary
- 【Linux】【CGI】【FAQ】代码中字符格式问题——类似 error: stray ‘\357’ in program
- PM竞品分析(Competitive Analysis)
- C语言学习笔记(1)--基本概念和函数用法
- 【HDU】 1018 Big Number
- 树
- 如何创建并运行java线程
- 第七周项目三(2)求三数最大值