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. 开源PLM软件Aras详解五 如何让ItemType显示在TOC上

    通过上一边ItemType我们大概了解,那么如何让ItemType显示在左侧的菜单上呢,又如何设置增删查改的权限呢,接下来将为演示. 在上一篇中,我们知道了ItemType的结构图,如下图 那么如何让 ...

  2. iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值实现方法:1.通过设置属性,实现页面间传值:2.委托delegate方式:3.通知notification方式:4.block方式:5.UserDefault或者文件方式:6.单例模式 ...

  3. LeetCode(二)

    实现Trie树 class TrieNode { public char val; public boolean isWord; public TrieNode[] children = new Tr ...

  4. 面试知识点总结之Java语言

    1.如果某个对象出现在字符串表达式中,如System.out.println(this+".class");,则会自动调用this.toString() 2.所有的类都是在对其第一 ...

  5. android studio小技巧

    1. 为了防止乱码,请将 android studio 右下角编码设置成 UTF-8 2. Ctri + Q 查看api 3 Ctri + Shift +U 大小写互换 4 Ctrl + Alt + ...

  6. nginx日志中访问最多的100个ip及访问次数

    nginx日志中访问最多的100个ip及访问次数 awk '{print $1}' /opt/software/nginx/logs/access.log| sort | uniq -c | sort ...

  7. PHP异步工作避免程序运行超时

    应用案例: 某SNS社区要求用户给自己好友(好友数量上百个)发送邮件,每封邮件内容不一,发送后提示发送完毕! 常用PHP写法 sendmail.php <?php $count=count($e ...

  8. JavaScript-插入concat,splice,截取slice

    拼接和截取:concat 拼接: var newArr=arr.concat(值1,值2,值3,值4,.....); 将值1值2,以及arr2中每个元素一次拼接到arr1结尾,返回新数组 强调: 1. ...

  9. MyBatis学习之路之configuration配置

    1.首先讲解的是MyBatis核心配置文件configuration.xml的配置 一个完整的configuration.xml配置顺序如下: properties,settings,typeAlia ...

  10. 《Linux内核设计与实现》读书笔记(十五)- 进程地址空间(kernel 2.6.32.60)

    进程地址空间也就是每个进程所使用的内存,内核对进程地址空间的管理,也就是对用户态程序的内存管理. 主要内容: 地址空间(mm_struct) 虚拟内存区域(VMA) 地址空间和页表 1. 地址空间(m ...