Count and Say
来源:互联网 发布:crt结束tomcat端口 编辑:程序博客网 时间:2024/06/06 00:34
class Solution {
public:
string revolution(string s)
{
string ret="";
int count=1;
char pre=s[0];
for(int i=0;i<s.size();i++)
{
if(s[i+1]==pre)
count++;
else
{
char tmp=count+'0';
ret=ret+tmp+pre;
pre=s[i+1];
count=1;
}
}
return ret;
}
string countAndSay(int n) {
string ret="1";
int j=1;
while(j<n){
ret=revolution(ret);
j++;
}
return ret;
}
};
public:
string revolution(string s)
{
string ret="";
int count=1;
char pre=s[0];
for(int i=0;i<s.size();i++)
{
if(s[i+1]==pre)
count++;
else
{
char tmp=count+'0';
ret=ret+tmp+pre;
pre=s[i+1];
count=1;
}
}
return ret;
}
string countAndSay(int n) {
string ret="1";
int j=1;
while(j<n){
ret=revolution(ret);
j++;
}
return ret;
}
};
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
- Server
- python-2-如何为元组中的每个元素命名,提高程序可读性?
- Block复制拷贝到堆的时机
- 搭建SSL服务器
- ArrayList简单使用
- Count and Say
- linux mongodb安装和配置启动图文详解
- 组织图结构图连线
- Java面试准备十五:数据库——索引
- POJ 3683 2-sat
- MySQL数据库下 delete from x where id=?会发生什么锁
- 计算机网络与Internet发展历史
- Python+Selenium框架设计篇之3-什么是POM
- html5+servlet文件上传