class Solution {
public:
vector<string> vs_;
Solution(){
string t("");
vs_.push_back(t);
for(int i = ; i< ;++i){
string t1 = vs_[i - ];
t = "";
int cnt = ,j ; for(j = ; j < t1.size() - ; ++j){
if(t1[j] == t1[j + ]){
++cnt;
}
else{
char s[] ="";
sprintf(s,"%d%c",cnt,t1[j]);
t += string(s);
cnt = ;
}
}
char s[] ="";
sprintf(s,"%d%c",cnt,t1[j]);
t += string(s);
vs_.push_back(t);
}
}
~Solution(){
vs_.clear();
} string countAndSay(int n) {
return vs_[n-];
}
};

Leetcode 38 Count and Say 传说中的递推的更多相关文章

  1. LeetCode - 38. Count and Say

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

  2. Leetcode 119 Pascal's Triangle II 数论递推

    杨辉三角,这次要输出第rowIndex行 用滚动数组t进行递推 t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1]; class Solution { public: ...

  3. LeetCode 38 Count and Say(字符串规律输出)

    题目链接:https://leetcode.com/problems/count-and-say/?tab=Description   1—>11—>21—>1211—>111 ...

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

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

  5. Java [leetcode 38]Count and Say

    题目描述: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, ...

  6. [leetcode]38. Count and Say数数

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

  7. [LeetCode] 38. Count and Say_Easy

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

  8. leetcode 38 Count and Say ---java

    这道题主要就是求一个序列,题目得意思就是 1 --> 11 --> 21 --> 1211 -->   111221 --> 312211 --> ..... 1个 ...

  9. LeetCode - 38. Count and Say(36ms)

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

随机推荐

  1. datagridview中使用checkbox问题。

    如果套用datagridview中的checkboxfield,生成的数据,会出现无法选择datagridview中数据项的问题,即checkbox不可以被鼠标点击,选中/取消选中.此checkbox ...

  2. VS调试在Win7(vista系列)操作系统下 HttpListener拒绝访问解决办法

    一. VS调试在Win7(vista系列)操作系统下 HttpListener无法绑定多个 指定IP.端口问题 来自:http://www.cnblogs.com/ryhan/p/4195693.ht ...

  3. mysql学习(二)

    (1)存储过程:存储过程是SQL语句和控制语句的预编译集合,以一个名称存储并作为一个单元处理: (2)存储过程优点:增强SQL语句的功能和灵活性,实现较快的执行速度,减少网络流量: (3)存储过程结构 ...

  4. Bootstrap 栅格系统(转载)

    源地址:http://www.cnblogs.com/linjiqin/p/3559800.html Bootstrap 栅格系统 目录1.简介2.栅格选项3.列偏移4.嵌套列5.列排序 1.简介Bo ...

  5. Pig Latin

    function translate(str) { //return str; var list = ['a','e','i','o','u']; if(list.indexOf(str[0]) &g ...

  6. GridView中实现CheckBox的全选

    GridView中实现CheckBox的全选 用服务器端的方法: 在页面上放一个gridview控件,配置好数据源,编辑列, <asp:GridView ID="GridView1&q ...

  7. linux links and lynx

    接下来,说一下links 和 lynx 的一些基本操作,首先你,需要安装这俩个软件 yum install links yum install lynx links links的功能键 一些常见功能按 ...

  8. NET Framework 4.0的安装失败处理

    如果是XP系统,这么做:1.开始——运行——输入cmd——回车——在打开的窗口中输入net stop WuAuServ2.开始——运行——输入%windir%3.在打开的窗口中有个文件夹叫Softwa ...

  9. 【模板】【转载】区间dp

    区间动态规划问题一般都是考虑,对于每段区间,他们的最优值都是由几段更小区间的最优值得到,是分治思想的一种应用,将一个区间问题不断划分为更小的区间直至一个元素组成的区间,枚举他们的组合 ,求合并后的最优 ...

  10. #笔记#JavaScript进阶篇一

    #JavaScript进阶篇 http://www.imooc.com/learn/10 #认识DOM #window对象 浏览器窗口可视区域监测—— 在不同浏览器(PC)都实用的 JavaScrip ...