38. Count and Say
来源:互联网 发布:网络复活赛 编辑:程序博客网 时间:2024/06/11 22:56
由于对String的很多用法我都一无所知,所以没有用java特有的方法。运行时间也是很慢,这个运行时间有45ms,而solution里最少的只有3ms。
2017.5.3
public static String countAndSay(int n) { if(n==1) return "1"; String res="1"; while(n>1){ res=say(res); n--; } return res; } public static String say(String str){ String say=""; char[] charIn=str.toCharArray(); for(int i = 0 ,count=1;i<charIn.length;i++){ if(i+1<charIn.length&&charIn[i]==charIn[i+1]){ count++; continue; }else{say+=String.valueOf(count)+charIn[i]; count=1; } } return say; }
0 0
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- 38. Count and Say
- UI适配原理及通用解决方法实战
- XStream 实现 javabean 与 xml 互转
- POJ 1190 生日蛋糕(DFS+剪枝)
- CSS中border:none和border:0的区别
- 多媒体问题
- 38. Count and Say
- 分针网—IT教育: 谈谈React那些小事
- map容器对象插入数据的4种方式讲解
- 概率图模型
- 05-杂项
- unity3d输入与控制——键盘事件
- 打地鼠
- 你知道Windows上有哪些奇技淫巧吗?
- 目前国内的高频交易系统的延迟做到了什么水平?