[LeetCode]38. Count and Say
来源:互联网 发布:ipad电视剧下载软件 编辑:程序博客网 时间:2024/05/16 05:03
Easy
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.
10ms:
public String countAndSay(int n) { if(n==1) return "1"; String[] ca = new String[n]; ca[0] = "1"; for(int i=1;i<n;i++){ String pre = ca[i-1]; StringBuilder now = new StringBuilder();; int count = 0; for(int j=0;j<pre.length();){ while(count+j<pre.length()&&pre.charAt(j)==pre.charAt(count+j)) count++; now.append(count).append(pre.charAt(j)); j += count; count = 0; } ca[i] = now.toString(); } return ca[n-1];}
0 0
- [LeetCode]38.Count and Say
- LeetCode --- 38. Count and Say
- LeetCode 38.Count and Say
- [Leetcode] 38. Count and Say
- 38. Count and Say LeetCode
- Leetcode 38. Count and Say
- leetcode 38. Count and Say
- [leetcode] 38. Count and Say
- LeetCode-38.Count and Say
- LeetCode *** 38. Count and Say
- leetcode 38. Count and Say
- LeetCode-38. Count and Say
- LeetCode 38. Count and Say
- LeetCode 38. Count and Say
- Leetcode - 38. Count and Say
- LeetCode 38. Count and Say
- Leetcode 38. Count and Say
- LeetCode 38. Count and Say
- hdu ---2010做题笔记(c++)
- 国内一个优秀的网络开源框架学习,轻量级网络框架学习NoHttp,可能是继Xutils之后的又一优秀框架
- 高效程序员的40个好习惯和行为方式
- effective stl 第49条:学会分析与STL相关的编译器诊断信息
- android studio for android learning (二十七) UI控件动态加载机制浅析
- [LeetCode]38. Count and Say
- HDU 5907 Find Q (简单题目)【BestCoder Round #88】
- 399. Evaluate Division
- Direct3D补充篇:表面缓冲区技术实现动画的流畅显示
- maven+springmvc+spring4+hibernate4整合
- 大型网站架构————核心原理-【可用性】4
- 全排列的非递归实现及递归实现
- Spring实现CXF服务端
- UVA11488 Trie