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. Linux下升级Python到3.5.2版本

    原文出处:https://www.cnblogs.com/tssc/p/7762998.html 本文主要介绍在Linux(CentOS)下将Python的版本升级为3.5.2的方法 众所周知,在20 ...

  2. Spring总结 1.装配bean

    本随笔内容要点如下: 依赖注入 Spring装配bean的方式 条件化装配 一.依赖注入 我理解的依赖注入是这样的:所谓的依赖,就是对象所依赖的其他对象.Spring提供了一个bean容器,它负责创建 ...

  3. elasticSearch6源码分析(6)http和transport模块

    1.http模块概述 The http module allows to expose Elasticsearch APIs over HTTP. The http mechanism is comp ...

  4. Spring事务传播属性介绍(一).required 和 reuqires_new

    Mandatory.Never.Not_Support传播属性分析传送门:https://www.cnblogs.com/lvbinbin2yujie/p/10260030.html Nested传播 ...

  5. 读jQuery源码释疑笔记3

    1.在jQuery.fn=jQuery.prototype中定义了方法:init, map, each , toArray, get, pushStack,   ready,  slice,first ...

  6. zoj Beautiful Number(打表)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2829 题目描述: Mike is very lucky, as ...

  7. windows开机提示文件损坏

    今早按部就班的开机,然后准备吃热干面,很多时候事情都是同步进行的... 然后眼前出现这样一个界面 心情果断灰暗下来,按照提示一步步操作,点enter进入高级选项,试过了安全模式启动.最后一次正确配置启 ...

  8. WebForm 基础学习

    C/S   客户端应用程序(Client/Server)  客户端——服务器端 两种技术      WinForm       WPF                                 ...

  9. 收集整理的oracle常用命令大全

    一.Oracle的启动和关闭 1.在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a.启动ORACLE系统 oracle>svrmgrl ...

  10. Java基础——Servlet(一)

    在学习Servlet之前,需要首先学习一些关联性的知识. 一.动态网页程序 动态网页:它是网页中的偏功能性的部分也是最重要的部分.它不是我们平时所看见的页面特效,展示的效果.而是,一种交互行为.比如, ...