LeetCode题解之 Reverse Only Letters
2024-10-19 11:44:47
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;
}
最新文章
- getElementsByClassName简单实现
- 如何运行python
- 43.Android之ListView中BaseAdapter学习
- Programs vs. processes
- virtual box硬盘扩容 不是加一块硬盘
- Java可变长参数方法调用问题
- kali linux 一些工具及命令集1(搜集DNS信息)
- C++中delete和delete[]的使用
- js中常用的Math方法总结
- Web应用中监听者的通知顺序按照DD中的定义顺序
- 51nod_1605:棋盘问题
- Python--Linux上安装Python
- 利用div绘制细线居中
- Spring Security(二十四):6.6 The Authentication Manager and the Namespace
- 关于jquery中on绑定click事件在苹果手机失效的问题
- :after伪类+content经典应用举例
- redis主从集群搭建及容灾部署(哨兵sentinel)
- 【LOJ】#2041. 「SHOI2015」聚变反应炉
- μCOS-II系统之事件(event)的使用规则及Semaphore实例
- windows下使用Git