1、题目描述

2、题目描述

利用栈实现逆序。

3、代码

 string reverseOnlyLetters(string S) {
if (S.size() == || S.size() == )
return S; stack<string> st;
for (string::iterator it = S.begin(); it != S.end(); it++) {
if ( isalpha(*it) ){
string sub = S.substr(it-S.begin(), );
st.push(sub);
}
} string res; for (auto it = S.begin(); it != S.end(); it++) {
if (isalpha(*it)) {
string sub = st.top();
st.pop();
res += sub;
} else {
string sub = S.substr(it - S.begin(),);
res += sub;
}
} return res;
}

LeetCode题解之 Reverse Only Letters的更多相关文章

  1. 【LeetCode】917. Reverse Only Letters 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 单指针 双指针 日期 题目地址: https:/ ...

  2. 【leetcode】917. Reverse Only Letters(双指针)

    Given a string s, reverse the string according to the following rules: All the characters that are n ...

  3. leetcode题解 7.Reverse Integer

    题目: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 E ...

  4. 《LeetBook》leetcode题解(7): Reverse Integer[E]——处理溢出的技巧

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 书的地址:https://hk029.gitbooks.io/leetboo ...

  5. LeetCode 题解之Reverse Words in a String

    1.题目描述 2.问题分析 使用一个vector存储每个单词. 3.代码 void reverseWords(string &s) { vector<string> v; for ...

  6. LeetCode题解之Reverse Bits

    1.题目描述 2.题目分析 使用bitset 类的方法 3.代码 uint32_t reverseBits(uint32_t n) { bitset<> b(n); string b_s ...

  7. [LeetCode 题解]: Reverse Nodes in K-Groups

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a li ...

  8. 【LeetCode题解】二叉树的遍历

    我准备开始一个新系列[LeetCode题解],用来记录刷LeetCode题,顺便复习一下数据结构与算法. 1. 二叉树 二叉树(binary tree)是一种极为普遍的数据结构,树的每一个节点最多只有 ...

  9. 【LeetCode题解】25_k个一组翻转链表(Reverse-Nodes-in-k-Group)

    目录 描述 解法一:迭代 思路 Java 实现 Python 实现 复杂度分析 解法二:递归(不满足空间复杂度) 思路 Java 实现 Python 实现 复杂度分析 更多 LeetCode 题解笔记 ...

随机推荐

  1. 【转】28个Unix/Linux的命令行神器

    下面是Kristóf Kovács收集的28个Unix/Linux下的28个命令行下的工具(原文链接),有一些是大家熟悉的,有一些是非常有用的,有一些是不为人知的.这些工具都非常不错,希望每个人都知道 ...

  2. 记住,永远不要在MySQL中使用“utf8”编码[转载]

    记住,永远不要在MySQL中使用“utf8”编码 原创: 无明.Adam 聊聊架构 6月15日 最近工作中我遇到了一个 bug,我试着通过 Rails 在以“utf8”编码的 MariaDB 中保存一 ...

  3. Bootstrap in ASP.NET MVC 5

    一,新建ASP.NET MVC 5 项目 Bootstrap 文件分布 引入到页面 1.定义.注意:不要包含有.min.的文件名称,会被忽略,因为在发布的时候编译器会加载min版的文件 2.在母版页中 ...

  4. mysql进行时

    1. 安装 参考 2. 远程连不上数据库 远程连接mysql时,提示“is not allowed to connect to this MySQL server” 解决(授权法): GRANT AL ...

  5. ResNet 论文研读笔记

    Deep Residual Learning for Image Recognition 原文链接 摘要 深度神经网络很难去训练,本文提出了一个残差学习框架来简化那些非常深的网络的训练,该框架使得层能 ...

  6. 传统项目转前端工程化——路由跳转时出现浏览器锁死和白屏【该死的同步ajax】

    [一开始我想到是该死的同步ajax,但我没验证,把他忽略了] 在探索前端工程化vue-cli做spa时,从搜索结果页跳转商品详情页时,因为详情页有很多ajax请求,并且都用的同步请求,就会导致请求时浏 ...

  7. ASP的不足与ASP.NET和ASP的区别

    ASP.Net和ASP的最大区别在于编程思维的转换,而不仅仅在于功能的增强.ASP使用VBS/JS这样的脚本语言混合html来编程,而那些脚本语言属于弱类型.面向结构的编程语言,而非面向对象,这就明显 ...

  8. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  9. multipartUpload上传图片到阿里云

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. 设计模式(9)--Composite(组合模式)--结构型

    1.模式定义: 组合模式属于对象的结构模式,有时又叫做“部分——整体”模式.组合模式将对象组织到树结构中,可以用来描述整体与部分的关系.组合模式可以使客户端将单纯元素与复合元素同等看待. 2.模式特点 ...