输入两个字符串S和T,字符串只包含小写字母和”#“,#表示为退格键,判断操作完退格键剩下字符串是否相等
例子:
S = “ab#c", T = "ad # c” 返回true,剩下的字符串是”ac“
S = “ab##", T = "c # d # ” 返回true,剩下的字符串是”“

class Solution {
public:
bool backspaceCompare(string S, string T) {
stack<char> stackS;
stack<char> stackT;
for(int i=; i<S.length(); i++) {
if(S[i] == '#' && !stackS.empty()) {
stackS.pop();
}
else if(S[i] != '#'){
stackS.push(S[i]);
}
}
for(int i=; i<T.length(); i++) {
if(T[i] != '#' && !stackT.empty()) {
stackT.pop();
}
else if(T[i] != '#') {
stackT.push(T[i]);
}
} return (stackS == stackT);
}
};

可关注公众号了解更多的面试技巧

LeetCode_844-Backspace String Compare的更多相关文章

  1. 【Leetcode_easy】844. Backspace String Compare

    problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...

  2. [LeetCode] Backspace String Compare 退格字符串比较

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  3. [Swift]LeetCode844. 比较含退格的字符串 | Backspace String Compare

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  4. LeetCode - Backspace String Compare

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  5. 844. Backspace String Compare判断删除后的结果是否相等

    [抄题]: Given two strings S and T, return if they are equal when both are typed into empty text editor ...

  6. 844. Backspace String Compare

    class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...

  7. leetcode-844 Backspace String Compare

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  8. [LeetCode] 844. Backspace String Compare 退格字符串比较

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  9. leetcode844 Backspace String Compare

    """ Given two strings S and T, return if they are equal when both are typed into empt ...

  10. C#LeetCode刷题之#844-比较含退格的字符串​​​​​​​(Backspace String Compare)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4030 访问. 给定 S 和 T 两个字符串,当它们分别被输入到空 ...

随机推荐

  1. js 大量数据优化,通用方法

    当页面渲染太多标签时,会出现卡顿的,典型就是类似table数据太多时,非常卡顿.如果选择分页,没必要讨论,这儿只讨论采用滚动的情况.解决思路很简单,就是页面不展示出来的元素,从页面上删除掉,最难点在于 ...

  2. ajax交互案例

    数据交互是前端很重要的一部分,静态页是基础,而交互才是网页的精髓.交互又分为人机交互和前后端数据交互,现阶段的互联网下,大部分的网站都要进行前后端数据交互,如何交互呢?交互的流程大概就是前端发送数据给 ...

  3. Vert.x Web 文档手册

    Vert.x Web 中英对照表 Container:容器 Micro-service:微服务 Bridge:桥接 Router:路由器 Route:路由 Sub-Route: 子路由 Handler ...

  4. 开发利器JRebel部署SpringBoot项目

    不要以为年纪轻轻就跌倒了人生谷底,未来还有更大的下降空间等着你. idea下载和安装JRebel 激活JRebel 访问https://my.jrebel.com/ 使用facebook或twitte ...

  5. 秒杀活动是否适合O2O生鲜行业的思考

    一.命题提出背景 公司是O2O生鲜行业,公司的业务部门提出要做秒杀活动.产品负责人听到后说没意义,秒杀不适合O2O生鲜.(产品负责人据说是阿里出来的P8,后来去微信,去永辉带运营.研发,做大佬,再后来 ...

  6. Visual Studio Code安装以及C/C++运行环境搭建

    众所周知VSCode是全宇宙最好用的编辑器 (雾 配置了很久,今日终于配置完成了,还是有点麻烦的,本文是为了方便一些不懂怎么配置的小白,以及还有一些美化教程. 一.安装 Visual Studio C ...

  7. 多线程——Runnable接口

    以实现Runable接口的方式创建线程比继承Thread类有很大的优越性,因为类不能多重继承,即一个类只能继承一个类,那么如果该类已经继承了一个类,就不能实现多线程了,但是可以通过实现Runable接 ...

  8. Go微服务全链路跟踪详解

    在微服务架构中,调用链是漫长而复杂的,要了解其中的每个环节及其性能,你需要全链路跟踪. 它的原理很简单,你可以在每个请求开始时生成一个唯一的ID,并将其传递到整个调用链. 该ID称为Correlati ...

  9. Mybatis源码解析,一步一步从浅入深(四):将configuration.xml的解析到Configuration对象实例

    在Mybatis源码解析,一步一步从浅入深(二):按步骤解析源码中我们看到了XMLConfigBuilder(xml配置解析器)的实例化.而且这个实例化过程在文章:Mybatis源码解析,一步一步从浅 ...

  10. WPS删除多余空白页

    WPS删除多余空白页 在实际工作中,我们在操作WPS文字的时候常常会遇到一种问题,就是当在文字占满整页的时候,文档常常会多出一页空白页的现象.如图1 图 1   对于WPS文字怎么删除空白页这个问题, ...