LeetCode OJ-- Count and Say
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的更多相关文章
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ学习
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...
- 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 ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
- 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 ...
- 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 ...
- 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 ...
- [LeetCode] 038. Count and Say (Easy) (C++/Python)
索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 038. Cou ...
随机推荐
- Tufurama CodeForces - 961E
Tufurama CodeForces - 961E 题意:有一部电视剧有n季,每一季有ai集.问有多少对i,j存在第i季第j集也同时存在第j季第i集. 思路:核心问题还是统计对于第i季,你要统计第i ...
- mysql-update时where条件无索引锁全表
1 5.3日数据处理需求 UPDATE md_meter set warranty_end_date = DATE_ADD(warranty_begin_date,INTERVAL 10 ...
- Collection record
复习大集合: 1.函数的参数:位置参数,关键字参数,动态参数 2.命名空间:内置命名空间,全局命名空间,局部命名空间 3.闭包函数:函数引用未定义的函数外非全局的变量叫做闭包,该函数称为闭包函数 4. ...
- 【N-Quens II】cpp
题目: Follow up for N-Queens problem. Now, instead outputting board configurations, return the total n ...
- Linux之如何进行固定IP、DNS等设置
前提:虚拟机Linux centOS6.6 Linux如何设置固定IP.dns.网关 1.切换到root账号 2.#cd /etc/sysconfig/network-scripts 进入网卡的设置 ...
- vmware克隆centos修改linux mac地址
故障背景: 在vmware workstation中了完全克隆了一个已经存在的centos的虚拟机,启动之后发现网卡没有启动.于是重启一下network服务,发现提示错误信息“Device eth0 ...
- Wordpress 自定义文章类型添加 Categoried、Tags
默认情况下 ,自定义文章类型没有分类和标签属性,需要通过 register_taxonomy_for_object_type 手动注册文章分类和标签,可以通过在 functions.php 或插件中添 ...
- redis linux 安装
安装 1): wget http://download.redis.io/releases/redis-5.0.2.tar.gz 2): tar xzf redis-5.0.2.tar.gz 3):c ...
- C#知识点<4>
1\C# 运算符重载 您可以重定义或重载 C# 中内置的运算符.因此,程序员也可以使用用户自定义类型的运算符.重载运算符是具有特殊名称的函数,是通过关键字 operator 后跟运算符的符号来定义的. ...
- AngularJs 特性 之 双向数据绑定
<!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UT ...