【LeetCode 38】报数
2024-09-06 03:33:35
【题解】
模拟题
【代码】
class Solution {
public:
string inttostr(int x){
string temp="";
while (x>0){
char key = (x%10)+'0';
temp= key+temp;
x/=10;
}
return temp;
}
string countAndSay(int n) {
string a = "1";
string b = "";
for (int i = 0;i < n-1;i++){
int len = a.size();
for (int j = 0;j < len;j++){
int k = j;
while (k+1<len && a[k+1]==a[k]) k++;
int num = k-j+1;
string snum = inttostr(num);
snum=snum+a[k];
b = b+snum;
j= k;
}
a = b;
b = "";
}
return a;
}
};
最新文章
- 使用spawn-fcgi管理php-cgi
- kakfa的常用命令总结
- 本地替换文件读取MYSQL密码
- hdoj 5392 Infoplane in Tina Town
- Object c中的alloc和init问题
- 1471. Tree(LCA)
- [转]setTimeout() 函数未定义错误
- Eclipse vs IDEA快捷键对比大全(win系统)
- spring 入门级程序示例
- .Net Core 2.0+ InfluxDB+Grafana+App Metrics 实现跨平台的实时性能监控
- c++ -->; sizeof()使用小结
- cdh集群认证命令
- 关于jstl中碰到的Property &#39;username&#39; not found on type java.lang.String异常
- java使用selenium版本不兼容解决汇总
- 三个解释——MVC的网址
- golang sublime text3 自动补全
- odoo开发笔记 -- context上下文
- Netty源码分析第7章(编码器和写数据)---->;第5节: Future和Promies
- bzoj3203【sdoi2013】保护出题人
- 什么是J2EE