Count and Say 【leetcode】
来源:互联网 发布:jtl 文件java 解析 编辑:程序博客网 时间:2024/05/21 07:05
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.
两个变量去扫描字符串,temp表示当前的值,n表示当前的值的个数。
class Solution {public: string countAndSay(int n) { string a,b; a="1"; for(int i=2;i<=n;++i) { b=""; int len=a.size(),n=1; char temp=a[0]; for(int j=1;j<len;++j) { if(a[j]!=temp) { b+='0'+n; b+=temp; temp=a[j]; n=1; } else n++; } b+='0'+n; b+=temp; swap(a,b); } return a; }};
- 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
- Dreamweaver中打开CodeSmith文件
- 网狐登录提示,服务器连接失败,请检查网络配置以及网络连接状况
- 2014年华为上机题及代码
- 数据结构全攻略--学好数据结构的必经之路
- ios离线读取上次网络请求的数据。
- Count and Say 【leetcode】
- 刚出的政治大纲解析
- linux内核空间与用户空间信息交互方法
- Java面试题之四
- MyEclipse 8.5 注册--取消MyEclipse Trial Expired解决办法
- nginx的重启
- Navigator 对象
- 几何概型
- FTP的执行行为和功能