LeetCode(38)题解: Count and Say
https://leetcode.com/problems/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.
思路:
题意有些模糊,看明白1211到111221就懂了。
AC代码:
class Solution {
public:
string countAndSay(int n) {
int tmp_n,count,k;
string tmp,tmp_res,a[n];
a[]="";
for(int i=;i<n;i++){
tmp=a[i-];
tmp_res="";
tmp_n=tmp.size();
k=;
count=;
for(int j=;j<tmp_n;j++){
if(tmp[j]==tmp[j-]){
count++;
continue;
}
else{
tmp_res.push_back(''+count);
tmp_res.push_back(tmp[j-]);
count=;
}
}
tmp_res.push_back(''+count);
tmp_res.push_back(tmp[tmp_n-]);
a[i]=tmp_res;
}
return a[n-];
}
};
LeetCode(38)题解: Count and Say的更多相关文章
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- Leetcode 简略题解 - 共567题
Leetcode 简略题解 - 共567题 写在开头:我作为一个老实人,一向非常反感骗赞.收智商税两种行为.前几天看到不止两三位用户说自己辛苦写了干货,结果收藏数是点赞数的三倍有余,感觉自己的 ...
- LeetCode 算法题解 js 版 (001 Two Sum)
LeetCode 算法题解 js 版 (001 Two Sum) 两数之和 https://leetcode.com/problems/two-sum/submissions/ https://lee ...
- 【LeetCode】222. Count Complete Tree Nodes 解题报告(Python)
[LeetCode]222. Count Complete Tree Nodes 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个 ...
- 【LeetCode算法-38】Count and Say
LeetCode第38题 The count-and-say sequence is the sequence of integers with the first five terms as fol ...
- 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 计数和读法
The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...
- Java [leetcode 38]Count and Say
题目描述: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, ...
随机推荐
- pmm metrics 数据采集来源
handler状态参数 mysql> show global status like '%handler%'; +----------------------------+----------- ...
- xmpp 登录注册小结
将XMPPStream放在APPDelegate,以便全局访问 #pragma mark - XMPP相关的属性和方法定义 /** * 全局xmppstream,只读属性 */ @property ( ...
- BZOJ4725: [POI2017]Reprezentacje ró?nicowe
$n \leq 1e5$,$x \leq 1e9$. 1e9呵呵,暴力处理$a_n$的前几项直到1e9.然后处理出差的数列,每次在这里面找,找得到就回答,找不到,那有贡献的只有$a_i-a_{i-1} ...
- Fabrice Bellard其人 ---- FFMPEG及其他……
有些计算机科学家的名字耳熟能详:阿兰·图灵(Alan Turing).高纳德(Donald Knuth).艾兹赫尔·戴克斯特拉(Edsger Dijkstra),这些人的名气甚至大于他们突破性的成就. ...
- go--time包
格式化字符串 转 时间戳 ////获取本地location toBeCharge := "2015-01-01 00:00:00" //待转化为时间戳的字符串 注意 这里的小时和分 ...
- ORACLE RMAN增量备份经典理解
http://blog.itpub.net/26118480/viewspace-1793548/
- ls 不是内部或外部命令
在C:\windows目录下新建一个文件 命名为 ls.bat 打开编辑这个文件 输入: @echo off dir 这两句保存即可.
- SpringBoot整合freemarker中自定义标签获取字典表的数据
因为在前端要根据字典表中的数据去将1.2这些值转换成对应的文字解释 1.首先要创建一个类去实现 TemplateDirectiveModel 类 @Component public class Dic ...
- spark学习常用的操作
首先,使用 ScalaIDE 或 IDEA 创建 Scala 的 Maven 工程.需要用到 spark-core,spark-sql,spark-streaming 的 jar 包,pom 文件如下 ...
- mysql 密碼忘記 解決
WINDOW 1.my.ini 加入 [mysqld] skip-grant-tables 2.mysql -uroot -p 登入 USE MYSQL: update user set passwo ...