leetcode 38
2024-09-24 18:05:45
38. Count and Say
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.
说真的刚开始真不知道这道题要干什么,英语有点差~~~
当明白是什么意思的时候又发现描述起来有点问题,语文有点差~~~
生硬的描述一下吧:1被读作“1个1” 或 11;11被读作“2个1”或21;21被读作“1个2,1个1”或1211;依次这样下去,输出第n个序列。
代码如下:
class Solution {
public:
string countAndSay(int n) {
string first = "";
for(int i = ; i < n; i++)
{
string ss = "";
int count = ;
for(int j = ; j < first.length(); j++)
{
if(first[j-] == first[j])
{
count ++;
}
else
{
ss = ss + (char)(count + '') + first[j-];
count = ;
}
}
first = ss + (char)(count + '') + first[first.length()-];
}
return first;
}
};
最新文章
- MR21、MR22和CK24的区别
- Hyper-V端口映射
- UOJ #149 [NOIP 2015] 子串
- 【PHP面向对象(OOP)编程入门教程】22.把对象串行化serialize()方法,__sleep()方法,__wakeup()方法
- Linux下多线程,断点续传,命令行下载工具axel
- MySQL常用技巧
- Android-The specified child already has a parent. You must call removeView() on the child&#39;s parent first.
- 谈谈PHP、Python与Ruby
- 常用mysql笔记
- PHP接口和抽象类的区别
- API接口开发简述示例
- 使用docker-compose搭建AspNetCore开发环境
- mysql简单主从复制(一)
- LINUX PID 1和SYSTEMD 专题
- Winio驱动在64位windows下无法使用的解决方法
- js增减日期
- E1. Array and Segments (Easy version)(暴力) &;&; E2. Array and Segments (Hard version)(线段树维护)
- n&&m and n||m 的区别
- Angular1.x directive(指令里的)的compile,pre-link,post-link,link,transclude
- 安装git之后,桌面图标出现很多的蓝色问号
热门文章
- 转载__直接拿来用!最火的Android开源项目(一)
- jquery ready 延迟
- 使用SVN进行项目版本管理
- 安装ipython import path error
- ruby的hash学习笔记例: 将字符串文本中的单词存放在map中
- EDE,DEDE网站搬家,DEDECMS搬家教程,一看就会
- C API 连接MYSQL
- [Flex] IFrame系列 —— 在flex的web应用中嵌入html的方法
- javascript 传递引用类型参数
- [POJ 1635] Subway tree systems (树哈希)