leetcode做题总结,题目Count and Say 2012/03/05
来源:互联网 发布:基德 知乎 编辑:程序博客网 时间:2024/06/08 18:24
这道题比较麻烦,但是其实也没什么技术含量,把每个数字存下来然后从前往后process即可。
public class Solution { public String countAndSay(int n) { String begin="1"; String end=begin; while(--n>0){ end=""; int bj=0; for(int i=0;i<begin.length();i++){ for(int j=i;j<begin.length();j++){ if(begin.charAt(i)==begin.charAt(j)){ bj++; if(j==begin.length()-1) end=end+bj+begin.charAt(i); i=j; }else{ end=end+bj+begin.charAt(i); bj=0; break; } } } begin=end; } return end; }}
Update 2015/08/29:注解一下上面的代码,上面的bj是用来统计数字的个数。
0 0
- leetcode做题总结,题目Count and Say 2012/03/05
- 【leetcode】第38题 Count and Say 题目+解析+代码
- LeetCode题目9 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
- [LeetCode] Count and Say
- Count and Say 【leetcode】
- [LeetCode] Count and Say
- STM32的存储器映射详解
- Princeton Algorithms: Part 2 [week 3: Maxflow and Mincut]
- Jquery Mobile文字和UI 组件如何同时居中(前端UI)?
- DataGrid使用总结
- 为什么HashMap取出的数据顺序和存储时的顺序不一致,如何解决?
- leetcode做题总结,题目Count and Say 2012/03/05
- 为什么写作《Qt Quick核心编程》
- [poj1833 排列]求数列的全排列中的后k项
- 10大热门的物联网初创公司
- Nor Flash 学习笔记
- <一>Ioc控制反转——手把手教学:如何配置并使用单元测试一个spring框架(附源码)
- c语言声明的特征
- 基于数组和基于链表线性表C++实现
- iOS--UISlider的使用方法详细