Count and Say
来源:互联网 发布:java string 添加空格 编辑:程序博客网 时间:2024/06/05 11:42
public class Solution { //dfs 算法还待写吧 http://www.cnblogs.com/huntfor/p/3849547.html public String countAndSay(int n) { if(n<=0) return null; String s = "1"; int cnt =1; for(int i=0; i<n-1 ; i++){ StringBuilder t = new StringBuilder(); for(int j=0; j< s.length(); j++){ if(j<s.length()-1 && s.charAt(j)==s.charAt(j+1)){ cnt++; }else{ t.append(cnt+""+s.charAt(j)); cnt=1; } } s = t.toString(); } return s; }}
难点在于不知道题目是什么意思,实际就是写然后读,然后按照读出的数组再写
ref: http://www.cnblogs.com/huntfor/p/3849547.html
dfs算法没搞
0 0
- LeetCode: Count and Say
- [LeetCode]Count and Say
- LeetCode Count and Say
- [Leetcode] Count and Say
- Count and Say
- Leetcode: Count and Say
- [LeetCode] Count and Say
- LeetCode Count and Say
- Count and Say
- [38]Count and Say
- Count and Say
- Count and Say
- Count and Say
- [LeetCode]Count and Say
- Count and Say
- Count and Say
- [LeetCode] Count and Say
- LeetCode-Count and Say
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- (1.2.1.2)单链表:有序链表合并、交集、差集
- 指针和数组的区别
- iotop实时监控磁盘
- short、int、long与byte之间的转换工具类
- Count and Say
- VS2013 密钥
- 2015/03/13开始模式识别与机器学习之旅
- Domain = FBSOpenApplicationErrorDomain, Code = 4
- ipTraf命令行网络工具
- eclipse集成html5插件
- ActiveMQ初体验
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- 博弈_总结