38. Count and Say徒手尝试#2(Done)
来源:互联网 发布:linux 输出文件夹大小 编辑:程序博客网 时间:2024/06/09 19:26
Solution
public class Solution { public String countAndSay(int n) { if (n < 1) { throw new IllegalArgumentException("Illegal argument for function countAndSay."); } String s = "1"; while (--n > 0) { StringBuilder tmp = new StringBuilder(); int i = 0, j = 0; while (j < s.length()) { if (s.charAt(j) != s.charAt(i)) { tmp.append(j - i); tmp.append(s.charAt(i)); i = j; } j++; } tmp.append(j - i); tmp.append(s.charAt(i)); s = tmp.toString(); } return s; }}
Problem#1
* String未初始化
* 注意不同类型之间不能随便转换
* char如何转成int
* 什么时候应当将String转换成charArray()
0 0
- 38. Count and Say徒手尝试#2(Done)
- 20_Valid Parentheses徒手尝试#2(Done)
- 27. Remove Element徒手尝试#2(Done)
- 66. Plus One徒手尝试#2(Done)
- 21. Merge Two Sorted Lists徒手尝试#2(Done)
- 24. Swap Nodes in Pairs徒手尝试#2(Done)
- 58. Length of Last Word徒手尝试#2(Done)
- 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
- 表、栈和队列
- 下定决心踏上软考之路
- 解读 OpenRegistryKey
- Java C++ 声明定义
- UNIX设计的思想。让每个程序只具有一项专门的能力,然后让它们合作
- 38. Count and Say徒手尝试#2(Done)
- [leetcode]287.Find the Duplicate Number
- leetcode(87).389. Find the Difference
- MySQL 操作总结(一)
- c语言里面log函数怎么用
- 读取联系人
- 大型网站技术架构
- java常用的第三方组件
- 深入理解ThreadLocal