LeetCode - Count and Say
来源:互联网 发布:男士双肩包 知乎 编辑:程序博客网 时间:2024/05/21 09:19
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) { string s;if(n<=0){return s;}s.push_back('1');if(n==1){return s;}int counter=1,num=0;char tmp;while(counter<n){string t;tmp=s[0];int i=0;while(i<s.size()){while(i<s.size()&&s[i]==tmp){num++;i++;}t.push_back(num+'0');t.push_back(tmp);num=0;tmp=s[i];}s.assign(t.begin(),t.end());counter++;}return s; }};
- 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
- Leetcode Count and Say
- LeetCode Count and Say
- LeetCode | Count and Say
- 多线程和并发中BlockingQueue的使用
- linux终端错误:Unable to find the ncurses libraries or the required header files
- C++成员变量与函数内存分配
- 如何将MSHFlexGrid控件中的内容导出为Excel
- 悔恨啊
- LeetCode - Count and Say
- commline interface lib libcli for Windows 7
- 排序算法/查找算法总结
- ruby 中输入字符串的判断方法
- SQL对数据库的操作(增删查改)
- Linux后台管理
- 对onreadystatechange属性的理解
- php长期定时刷新一个页面
- Class Profile for MBA Class of 2014*