https://oj.leetcode.com/problems/count-and-say/

求经过n次变换后,变成了什么。

1  11  21  1211   111221

ps. 3 变成 ‘3’,为 3 + '0'

class Solution {
public:
string countAndSay(int n) {
string ans_str;
vector<int> input;
input.push_back(); // the first time
vector<int> output;
for(int i = ;i<n;i++)
{
fun(input,output);
input = output;
} for(int i = ;i<input.size();i++)
ans_str.push_back(''+input[i]);
return ans_str;
}
void fun(vector<int> input,vector<int> &output)
{
output.clear();
int itr = ;
while(itr<input.size())
{
int value = input[itr];
int times = ;
while(itr<input.size()&&input[itr]==value)
{
times++;
itr++;
}
output.push_back(times);
output.push_back(value);
}
}
};

LeetCode OJ-- Count and Say的更多相关文章

  1. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  2. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  3. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  4. LeetCode OJ学习

    一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...

  5. LeetCode OJ 297. Serialize and Deserialize Binary Tree

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  6. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

  7. LeetCode OJ 之 Maximal Square (最大的正方形)

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

  8. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  9. LeetCode OJ:Serialize and Deserialize Binary Tree(对树序列化以及解序列化)

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  10. [LeetCode] 038. Count and Say (Easy) (C++/Python)

    索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 038. Cou ...

随机推荐

  1. python爬虫的基本思路

    爬虫:请求网站并提取数据的自动化程序. 流程: 发送请求 -> 获取数据 -> 解析数据 -> 存储数据

  2. Python中的dict

    dict_lst = [ ('字典的键必须可哈希',), ('字典的键重复覆盖',), ('字典可迭代') ('增',), ('删',), ('改',), ('查',), ('练习',), ] 字典的 ...

  3. 时间转换,django的时间设置,re模块简单校验密码和手机号

    时间转换和密码,手机的re模块简单校验 import re,time def check_userinfo(request): pwd = request.POST.get("pwd&quo ...

  4. proc的妙用

    今天在在公司做网络驱动开发测试时,随机包出现收包计数停止的现象,当时怀疑是DMA rx buffer不足导致,想通过对比收发包正常和收发包不正常是DMA相关寄存器的情况. 后跟踪代码,若在收发包里面增 ...

  5. 读《深入理解jvm虚拟机》之长期存活对象进入老年代,有感!!!!

    关于这一段代码 有几个不是让人很理解的地方,我一一说来. 1.Desired survivor size 524288 bytes 关于这个512KB空间是怎么来的,JVM有这样一个参数: -XX:T ...

  6. 【Directory】文件操作(初识文件操作二)

    上篇我们说了关于文件的创建删除更改可以通过File这个类来完成.对于目录的操作其实File类也可以完成创建删除等相关的操作.用法跟文件的方法大致相同. 那么下面就一起来看一下关于目录相关的用法. 一, ...

  7. Js中的undefined和not defined

    1.undefined 已经声明,但未赋值 2.not defined 未声明,报错

  8. appium环境搭建(python+windows)

    1.搭建Android开发环境 参见:http://blog.sina.com.cn/s/blog_44d19b500102voa7.html   2.安装Node.js 下载地址:https://n ...

  9. IOS架构

    iPhone OS(现在叫iOS)是iPhone, iPod touch 和 iPad 设备的操作系统. 1,Core OS: 是用FreeBSD和Mach所改写的Darwin, 是开源.符合POSI ...

  10. git基础之常用操作

    一.版本提交: (1)git add 文件名 (2)git commit -m "版本提交信息" 注:git分两个区:工作区+版本库 在电脑中看到的文件夹就是工作区 有一个隐藏的. ...