Leetcode38 Count and Say
来源:互联网 发布:2345网络电视直播 编辑:程序博客网 时间:2024/06/09 23:06
Count and Say
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 integern , generate thenth sequence.Note: The sequence of integers will be represented as a string.
Solution
- 没什么算法上的难度,具体就是数每一个数都有多少个。
public class Solution { public String countAndSay(int n) { if(n<1) return ""; StringBuffer sb = new StringBuffer(); StringBuffer temp = new StringBuffer(); sb.append(1); for(int i=1;i<n;i++){ for(int j=0;j<sb.length();){ char c = sb.charAt(j); int len = 0; while(j<sb.length()&&sb.charAt(j)==c){ len++; j++; } temp.append(len); temp.append(c); } sb = temp; temp = new StringBuffer(); } return sb.toString(); }}
0 0
- [LeetCode38]Count and Say
- Leetcode38 Count and Say
- leetcode38 Count and Say
- leetcode38---Count and Say
- leetcode38. Count and Say
- leetcode38: Count and Say
- Leetcode38: Count and Say
- LeetCode38. Count and Say
- leetcode38. Count and Say
- 【LeetCode38】【Count and Say】StringBuilder
- LeetCode38——Count and Say
- LeetCode38——Count and Say
- LeetCode38 Count and Say(C语言解决)
- LeetCode: Count and Say
- [LeetCode]Count and Say
- LeetCode Count and Say
- [Leetcode] Count and Say
- Count and Say
- QT中qlistwidget和qtableview用法
- 一切成功源于积累——20150727 0728 0729 欧美 三连惨案。。。。每天损失20++ 我究竟在急什么
- Android广告的Activity收集
- C#中各种计时器
- 学习笔记(八)对象的集合(二)
- Leetcode38 Count and Say
- MPEG- 4 算法标准特性
- 研发中间件介绍-异步消息可靠推送Notify
- 配置文件读取
- iOS5中UIViewController的新方法
- Android开发系列通信篇之EventBus
- 电信百兆宽带使用攻略
- Jetty
- android相关目录的存取方式与函数解析---全