【LeetCode 38】报数
【题解】
模拟题
【代码】
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;
}
};
【LeetCode 38】报数的更多相关文章
- [leetcode] 38. 报数(Java)(字符串处理)
38. 报数 水题 class Solution { public String next(String num) { String ans = ""; int i = 0; wh ...
- Leetcode 38.报数 By Python
报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 "one 1" ...
- LeetCode 38.报数(Python3)
题目: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 "one 1& ...
- C#刷遍Leetcode面试题系列连载(2): No.38 - 报数
目录 前言 题目描述 相关话题 相似题目 解题思路: 运行结果: 代码要点: 参考资料: 文末彩蛋 前言 前文传送门: C# 刷遍 Leetcode 面试题系列连载(1) - 入门与工具简介 上篇文章 ...
- Leetcode题库——38.报数
@author: ZZQ @software: PyCharm @file: countAndSay.py @time: 2018/11/9 14:07 说明:报数序列是一个整数序列,按照其中的整数的 ...
- 【leetcode算法-简单】38. 报数
[题目描述] 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 12. 113. 214. 12115. 1112211 被读作 "one 1&qu ...
- [LeetCode] 38. Count and Say 计数和读法
The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...
- Java实现 LeetCode 38 外观数列
38. 外观数列 「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述.前五项如下: 1 11 21 1211 111221 1 被读作 "one 1" ...
- LeetCode - 38. Count and Say
38. Count and Say Problem's Link ------------------------------------------------------------------- ...
随机推荐
- [CF1149E]Election Promises
可以猜想这题和sg函数有关.(反正也没有什么其它可用的算法) 因为是个DAG,所以可以先求出每个点的sg值.考虑怎样求答案. 根据sg函数证明的思路,我们可以考虑构造一个权值,使得以下三个条件满足: ...
- django-admin.py和manage.py的用法
[简介] django-admin.py是Django的一个用于管理任务的命令行工具.本文将描述它的大概用法. 另外,在每一个Django project中都会有一个manage.py.manage. ...
- C# JS 前后端互传数据
---恢复内容开始--- 后端: public void ProcessRequest(HttpContext context) { context.Response.ContentType = &q ...
- Leaflet-Leafletv0.7使用leaflet-bing-layer
digidem/leaflet-bing-layer: Bing Maps Layer for Leaflet v1.0.0:从标题就可以看出要Leaflet v1.0.0才能用.其实leaflet ...
- *arg,**kwargs的参数作用的疑惑
先来看个例子: def foo(*args, **kwargs): print 'args = ', args print 'kwargs = ', kwargs print '----------- ...
- java基础知识-基本概念
1.1 java语言有哪些优点? 1.java语言为纯面向对象的语言. 2.平台无关性.java语言的优点便是“一次编译,到处执行”.编译后的程序不会被平台所约束,因此java语言有很好的移植性. 3 ...
- UVALive 4992 Jungle Outpost(半平面交判存)
Jungle Outpost Time limit: 15.000 seconds Description There is a military base lost deep in the jung ...
- 分布式ID的雪花算法及坑
分布式ID生成是目前系统的常见刚需,其中以Twitter的雪花算法(Snowflake)比较知名,有Java等各种语言的版本及各种改进版本,能生成满足分布式ID,返回ID为Long长整数 但是这里有一 ...
- C#log4net的使用
一,下载log4net.dll,在项目中添加引用 二,在站点根目录添加,配置文件(log4net.xml), <file value="logs/logfile.txt"/& ...
- windows修改docker的默认存放位置
docker默认存储到c盘,我需要移动到其他盘. 参考了网上很多资料,结果要么移动不了,要么重启docker就回到c盘了. 最后参考docker的官方论坛,找到了解决方案.https://forums ...