leetcode 38
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;
}
};
leetcode 38的更多相关文章
- [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 ------------------------------------------------------------------- ...
- LeetCode 38 Count and Say(字符串规律输出)
题目链接:https://leetcode.com/problems/count-and-say/?tab=Description 1—>11—>21—>1211—>111 ...
- LeetCode(38)题解: Count and Say
https://leetcode.com/problems/count-and-say/ 题目: The count-and-say sequence is the sequence of integ ...
- Leetcode 38.报数 By Python
报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 "one 1" ...
- [leetcode] 38. 报数(Java)(字符串处理)
38. 报数 水题 class Solution { public String next(String num) { String ans = ""; int i = 0; wh ...
- Leetcode 38 Count and Say 传说中的递推
class Solution { public: vector<string> vs_; Solution(){ "); vs_.push_back(t); ; i< ;+ ...
- leetcode 38 Count and Say ---java
这道题主要就是求一个序列,题目得意思就是 1 --> 11 --> 21 --> 1211 --> 111221 --> 312211 --> ..... 1个 ...
随机推荐
- Linux命令(19)用户权限管理:chown
linux用户权限: Linux/Unix 是多人多工作业系统,所有的档案皆有拥有者.利用 chown 可以将档案的拥有者加以改变. 一般来说,这个指令只有是由系统管理者(root)所使用,一般使用者 ...
- ios8消息快捷处理——暂无输入框
if (isiOS8) { //ios8的远程推送注册 NSSet *set = nil; #if 1 //1.创建消息上面要添加的动作(按钮的形式显示出来) UIMutableUserNotific ...
- 使用Visual Studio 2013 调试 MASM 汇编程序!
原文地址:http://kipirvine.com/asm/debug/vstudio2013/index.htm Using the Microsoft Visual Studio 2013 Deb ...
- Opensturt和Struct区别
1 OpenStruct和Struct区别,Opestruct你需要创建时,直接给属性赋值,而Struct需要先定义属性后 ,再给属性赋值.选择哪个就看你对属性赋值的时机, 2 Struct和Open ...
- 20145305解佳玲 《Java程序设计》第1周学习总结
教材学习内容总结 第一章 Java平台概论 1.先了解了JAVA的历史 2.Java三大平台:Java SE.Java EE与Java ME 3.Java SE的四个组成部分:JVM.JRE.JDK与 ...
- 93、App Links (应用程序链接)实例
•网页端statements.json文件配置说明 package_name :APP包的名. sha256.... : APP的签名. •应用Manifest文件声明说明 <ap ...
- NLog文章系列——如何配置NLog(转)
NLog使用方法 作者:Jaros?aw Kowalski <> 翻译:CrazyCoder(由衷感谢他的热心!!) 原文:http://www.nlog-project.org/conf ...
- php读取数据库数据,出现中文乱码(数据库中没有出现乱码)
添加header(“content-type: text/html; charset=utf-8”) php header() 函数向客户端发送原始的 HTTP 报头, 认识到一点很重要,即必须在任何 ...
- C++学习25 纯虚函数和抽象类
在C++中,可以将成员函数声明为纯虚函数,语法格式为: ; 纯虚函数没有函数体,只有函数声明,在虚函数声明结尾加上=0,表明此函数为纯虚函数. 最后的=0并不表示函数返回值为0,它只起形式上的作用,告 ...
- rsync 目录 斜杠
源: 不带:同步 目录和内容 带/: 只同步内容 target目录: 待. -Warv --delete -W, --whole-file copy files whole ( ...