题目链接

【题解】

模拟题

【代码】

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】报数的更多相关文章

  1. [leetcode] 38. 报数(Java)(字符串处理)

    38. 报数 水题 class Solution { public String next(String num) { String ans = ""; int i = 0; wh ...

  2. Leetcode 38.报数 By Python

    报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 "one 1" ...

  3. LeetCode 38.报数(Python3)

    题目: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作  "one 1& ...

  4. C#刷遍Leetcode面试题系列连载(2): No.38 - 报数

    目录 前言 题目描述 相关话题 相似题目 解题思路: 运行结果: 代码要点: 参考资料: 文末彩蛋 前言 前文传送门: C# 刷遍 Leetcode 面试题系列连载(1) - 入门与工具简介 上篇文章 ...

  5. Leetcode题库——38.报数

    @author: ZZQ @software: PyCharm @file: countAndSay.py @time: 2018/11/9 14:07 说明:报数序列是一个整数序列,按照其中的整数的 ...

  6. 【leetcode算法-简单】38. 报数

    [题目描述] 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 12. 113. 214. 12115. 1112211 被读作  "one 1&qu ...

  7. [LeetCode] 38. Count and Say 计数和读法

    The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...

  8. Java实现 LeetCode 38 外观数列

    38. 外观数列 「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述.前五项如下: 1 11 21 1211 111221 1 被读作 "one 1" ...

  9. LeetCode - 38. Count and Say

    38. Count and Say Problem's Link ------------------------------------------------------------------- ...

随机推荐

  1. php ord()函数 语法

    php ord()函数 语法 作用:返回字符串的首个字符的 ASCII 值.直线电机生产厂家 语法:ord(string) 参数: 参数 描述 string 必须,要从中获得ASCII值的字符串 说明 ...

  2. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification (点在多边形内模板)

    In the Personal Communication Service systems such as GSM (Global System for Mobile Communications), ...

  3. Microsoft SQL Server(sql server 关系型数据库管理系统)

    sql server一般指Microsoft SQL Server 关系型数据库管理系统 Microsoft SQL Server 是一个全面的数据库平台,使用集成的商业智能 (BI)工具提供了企业级 ...

  4. [信息学奥赛一本通oj1741]电子速度 题解

    对于$100 \%$的数据,$1≤n,m≤1e6 \ \ \ 0<=x_i,y_i<20170927 \ \ \ 1≤l_i,r_i≤n $ $Solution:$ 一开始没看懂题.后来大 ...

  5. 报错记录(xml抬头报错)

    报错记录(xml抬头报错) Referenced file contains errors (http://www.springframework.org/schema/beans/spring-be ...

  6. MVC 入门

    MVC是什么? MVC是一个框架模式,它用于把应用程序的输入.处理和输出进行强制性的分开.使用MVC应用程序被分成三个核心部件:模型.视图.控制器.它们各自处理自己的任务.最典型的MVC就是JSP+S ...

  7. 面试题30:包含min函数的栈

      思路: 1.首先将栈的基本结构写出 #初始化栈的写法 def __init__(self): self.stack = [] #栈的压入 (加self是实例化,如果前面加入静态装饰器啥的,就不需要 ...

  8. Bootstrap+Ajax+HTML 动态表格分页

      1.HTML页面:(bootstrap的模态框) 触发模态框: <div class="col-lg-6"> <div class="input-g ...

  9. django-2-目录结构

    django是MVC或者叫MTV框架

  10. “希希敬敬对”队软件工程第九次作业-beta冲刺第五次随笔

    “希希敬敬对”队软件工程第九次作业-beta冲刺第五次随笔 队名:  “希希敬敬对” 龙江腾(队长) 201810775001 杨希                   201810812008 何敬 ...