Leetcode38. Count and Say

分析:根据题意,数列的下一项就是统计上一项中每个数字出现的次数,理解清楚题意就很简单了

 class Solution {
public:
string solve(string s){
string p="";
int len=s.length();
int count=;
for(int i=;i<=len;i++){
if(s[i]==s[i-]){
count++;
}else{
p+=count+'';
p+=s[i-];
count=;
}
}
return p;
}
public:
string countAndSay(int n) {
string res="";
for(int i=;i<=n;i++)
res=solve(res);
return res;
}
};

Leetcode字符串专题的更多相关文章

  1. LeetCode 字符串专题(一)

    目录 LeetCode 字符串专题 <c++> \([5]\) Longest Palindromic Substring \([28]\) Implement strStr() [\(4 ...

  2. 【leetcode 字符串处理】Compare Version Numbers

    [leetcode 字符串处理]Compare Version Numbers @author:wepon @blog:http://blog.csdn.net/u012162613 1.题目 Com ...

  3. NOIP2018提高组金牌训练营——字符串专题

    NOIP2018提高组金牌训练营——字符串专题 1154 回文串划分 有一个字符串S,求S最少可以被划分为多少个回文串. 例如:abbaabaa,有多种划分方式.   a|bb|aabaa - 3 个 ...

  4. LeetCode树专题

    LeetCode树专题 98. 验证二叉搜索树 二叉搜索树,每个结点的值都有一个范围 /** * Definition for a binary tree node. * struct TreeNod ...

  5. leetcode 字符串类型题

    1,Vaild Palindrome bool isPalindrome(string& s) { transform(s.begin(), s.end(), s.begin(), tolow ...

  6. leetcode 字符串中的第一个唯一字符

    给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 案例: s = "leetcode" 返回 0. s = "loveleetcod ...

  7. leetcode 字符串动态规划总结

    问题1:leetcode 正则表达式匹配 请实现一个函数用来匹配包括'.'和'*'的正则表达式.模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次). 在本题中,匹配 ...

  8. 字符串专题:map POJ 1002

    第一次用到是在‘校内赛总结’扫地那道题里面,大同小异 map<string,int>str 可以专用做做字符串的匹配之类的处理 string donser; str [donser]++ ...

  9. PHP 截取字符串专题

    1. 截取GB2312中文字符串 < ?php//截取中文字符串function mysubstr($str, $start, $len) {    $tmpstr = "" ...

随机推荐

  1. (45)C#网络3 socket

    一.TCP传输 using System.Net.Sockets; 1.最基本客户端连服务器 服务端运行后一直处于监听状态,客户端每启动一次服务端就接收一次连接并打印客户端的ip地址和端口号.(服务端 ...

  2. Codeforces 667D World Tour【最短路+枚举】

    垃圾csdn,累感不爱! 题目链接: http://codeforces.com/contest/667/problem/D 题意: 在有向图中找到四个点,使得这些点之间的最短距离之和最大. 分析: ...

  3. <!--#include 引入失败

    在html中使用了<!--#include file="a.html">,结果发现页面上并没有引入到a.html页面,F12看是以注释的形式展示出来了,百度了很久. 最 ...

  4. Hbase优化总结

    1.JVM参数优化: –Xmn=12G –Xms=24G  -Xmx=24G  根据实际机器情况调整,一般为整个机器内存的一半,同时建议regionServer的堆内存建议不要超过32G ; -XX: ...

  5. 【Todo】【读书笔记】Linux高性能服务器编程

    在读 /Users/baidu/Documents/Data/Interview/服务器-检索端/<Linux高性能服务器编程.pdf> 其实之前读过,要面试了,需要温习. P260 So ...

  6. linux shell操作

    ---------------------------------------------------- 原文:http://unix.stackexchange.com/questions/2863 ...

  7. [Tools] Convert SVG to a PDF in Node with PDFKit and SVG.js

    Given a epxress application and an svg template, we want to draw some text, date onto it and convert ...

  8. Android:图片中叠加文字,支持拖动改变位置

    之所以做了这么一个Demo,是由于近期项目中有一个奇葩的需求:用户拍摄照片后,分享到微信的同一时候加入备注,想获取用户在微信的弹出框输入的内容.保存在自己的server上.而其实,这个内容程序是无法获 ...

  9. 基于canvas和Web Audio的音频播放器

    wavesurfer.js是一款基于HTML5 canvas和Web Audio的音频播放器插件.通过wavesurfer.js你能够使用它来制作各种HTML5音频播放器,它能够在各种支持 Web A ...

  10. Ubuntu 16.04 同时使用python3.5

    Python 3.x版本使用pip3,它会把你想下载的包放到usr/local/lib/python3.5/dist-packages/下,而非usr/local/lib/python2.7/dist ...