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 ...
随机推荐
- Jquery 生成时钟
$(function(){ showTime(); }): function showTime () { var curtime=new Date(); $(".getDateTime&qu ...
- AngularJS学习---Routing(路由) & Multiple Views(多个视图) step 7
1.切换分支到step7,并启动项目 git checkout step- npm start 2.需求: 在步骤7之前,应用只给我们的用户提供了一个简单的界面(一张所有手机的列表),并且所有的模板代 ...
- LaTex学习笔记(一):review
1.百分号 \% 2.下标 b_{ij} 3.表格(excel2latex) 符号说明 \begin{table}[H] \centering \begin{tabular}{m{100pt}< ...
- mvc深入理解
对于v和c好理解, 对于model分为数据对象模型和业务逻辑模型,一般为一个类,数据对象模型包含对一个具体数据表的相关操作,业务逻辑模型为处理一些业务逻辑.
- try catch finally return之间的关系
一.try catch finally return之间的关系: 正在写dsoFramer的时候,同事突然说面试的时候问的一个问题,catch和return那个先执行,我瞬间迷茫了,然后整理了整理,稍 ...
- 解决AndroidADT自带Eclipse编辑器不能自动代码提示的问题
今天发现,我下载的AndroidADT开发套装中自带的Eclipse没有自动代码提示功能.通过参考http://blog.csdn.net/coolszy/article/details/724195 ...
- Server Transfer()和Response.Redirect()的使用
一.Server Transfer() Server.Transfer:对于当前请求,终止当前页的执行,并使用指定的页url路径来开始执行一个新页. 1. Server.Transfer只能够转跳到本 ...
- centos 6.5 + php5.5.31 fastcgi (fpm) 编译安装
yum intsall zlib zlib-devel //gzip 压缩和解压 yum install openssl openssl-devel yum install libxml2 libxm ...
- HtmlHelper和强类型转换
MVC HtmlHelper;1.Url():<%= Html.ActionLink("用户列表","方法","控制器") %> ...
- FastReport代码计算高度
Dim iHeight As Double Dim columnData_form As DataSourceBase iHeight=Page1.TopMarg ...