Count and Say
来源:互联网 发布:mac snow ball 编辑:程序博客网 时间:2024/06/05 09:20
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
1
is read off as "one 1"
or 11
.11
is read off as "two 1s"
or 21
.21
is read off as "one 2
, then one 1"
or 1211
.
Given an integer n, generate the nth sequence.
Note: The sequence of integers will be represented as a string.
class Solution {public: string countAndSay(int n) { if(n == 0) return "1"; string result = "1"; for(int i=2;i<=n;i++){ string temp = ""; char tempChar = result[0]; int count = 1; for(int j=1;j<result.length();j++){ if(result[j] == tempChar){ count++; }else{ temp.append(1,char(count+'0')); temp.append(1,tempChar); count = 1; tempChar = result[j]; } } temp.append(1,char(count+'0')); temp.append(1,tempChar); result = temp; } return result; }};
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
- Ubuntu以太网显示连接,但是firefox无法上网问题
- SQL笔记(11)_第十一章 函数
- 成为Java GC专家(5)—Java性能调优原则
- @官方渠道IOS应用审核加速上架AppStore服务
- popwindow的使用
- Count and Say
- android:versionCode和android:versionName 用途
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(二)
- 敏感词过滤,PHP实现的Trie树
- java采用 java.util.Properties类读取.properties配置文件
- DenseBox: Unifying Landmark Localization with End to End Object Detection
- 关于时间,日期,星期,月份的算法(Java中Calendar的使用方法)
- 递归练习
- Java 网络学习