Leetcode 38 Count and Say 传说中的递推
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 传说中的递推的更多相关文章
- LeetCode - 38. Count and Say
38. Count and Say Problem's Link ------------------------------------------------------------------- ...
- 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: ...
- 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, ...
- [leetcode]38. Count and Say数数
The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...
- [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 ...
- leetcode 38 Count and Say ---java
这道题主要就是求一个序列,题目得意思就是 1 --> 11 --> 21 --> 1211 --> 111221 --> 312211 --> ..... 1个 ...
- 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 ...
随机推荐
- 三级设置页面管理测试demo
#include "PhoneBookWindow.h"#include "xWindow/xWindow.h"#include "hardwareD ...
- JQuery UI Autocomplete与jquery.autocomplete.js
程序中要把一个select改成可以下拉搜索的,就想到了使用下autocomplete.js大概是这么个东西. 问了下同学,推荐我使用Jquery Ui autocomplete,下载下来开始调试使用, ...
- @gettrcname.sql
http://www.eygle.com/archives/2007/05/script_gettrcname.html 最近有很多朋友问起<深入浅出Oracle>一书中的一个脚本gett ...
- Git常用命令(自己总是忘记,整理在这里)
1.git init 初始化一个空的git仓库 2.git clone +SSH地址 clone新的项目到本地 3.git add git add file 4.git commi ...
- 关于Control flow
1.一个package包含一个control flow并且一个或多个data flow. (这个项目叫做 Integration services project,提供了三种不同类型的control ...
- UWP深入学习四:动画及图像
Storyboarded animations Key-frame animations and easing function animations 缓动函数 缓动函数支持你将自定义数学公式应用到动 ...
- 张小龙《微信背后的产品观》之PPT完整文字版
微信回顾 433天,一亿用户 成为移动互联网的新入口 启动(2010年11月19日) 用户数突破1亿 1.0 1月26日 2.0 5月10日 语音对讲 2.5 8月3日 查看那附近的人 3.0 10月 ...
- asp控件Repeater运用
双层repeater嵌套 <asp:Repeater ID="rpt_dataRepeatgroup" runat="server" OnItemData ...
- 多线程JAVA篇(一)
解析AsyncTask源码之前,首先讲述与之相关的Java线程知识: 知识点清单 1.Thread类 2.Runnable接口 3.Callable接口 4.synchronized关键字 5.vol ...
- Android性能优化方法(五)
有时候,我们的页面中可能会包含一些布局,这些布局默认是隐藏的,当用户触发了一定的操作之后,隐藏的布局才会显示出来.比如,我们有一个Activity用来显示好友的列表,当用户点击Menu中的“导入”以后 ...