leetcode做题总结,题目Count and Say 2012/03/05
2014-11-29 09:51
375 查看
这道题比较麻烦,但是其实也没什么技术含量,把每个数字存下来然后从前往后process即可。
Update 2015/08/29:注解一下上面的代码,上面的bj是用来统计数字的个数。
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是用来统计数字的个数。
相关文章推荐
- leetcode做题总结,题目Swap Nodes in Pairs 2012/02/14
- leetcode做题总结,题目Merge Two Sorted Lists 2012/03/30
- leetcode做题总结,题目Add Two Numbers /Add Binary 2011/11/01&2012/04/02
- leetcode做题总结,题目Search in Rotated Sorted Array I/II 2012/03/02-12/04/09
- leetcode做题总结,题目Search a 2D MatrixI/II 2012/04/06
- LeetCode题目9 Count and Say
- leetcode做题总结,题目Gray Code 2012/05/20
- leetcode做题总结,题目First Missing Positive 2012/03/08
- leetcode做题总结,题目Sort List 2013/11/16
- leetcode做题总结,题目Search Insert Position 2012/03/03
- leetcode做题总结,题目Plus One 2012/04/02
- leetcode做题总结,题目Pow(x, n)-------- 2012/03/19
- leetcode做题总结,题目Convert Sorted List to Binary Search Tree 2012/10/02
- leetcode做题总结,题目Spiral Matrix I/II 2012/03/24
- leetcode做题总结,题目Merge Sorted Array 2012/05/20
- leetcode做题总结,题目Set Matrix Zeroes 2012/04/06
- leetcode做题总结,题目Generate Parentheses 2012/02/12
- leetcode做题总结,题目Rotate List 2012/03/27
- leetcode做题总结,题目Search for a Range 2012/03/02
- leetcode做题总结,题目Copy List with Random Pointer 2013/10/03