输入两个字符串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. 通过原型继承理解ES6 extends 如何实现继承

    前言 第一次接触到 ES6 中的 class 和 extends 时,就听人说这两个关键字不过是语法糖而已.它们的本质还是 ES3 的构造函数,原型链那些东西,没有什么新鲜的,只要理解了原型链等这些概 ...

  2. 面试贴:java异常小结

    java的异常处理在面试中通常是个敏感的话题,这里我从整体框架方面稍微作一下我的小结. java的异常都继承Throwable这个类,也就是都可以抛出来的异常,在这个祖先类下,又分为如下子类: 1.E ...

  3. 遇到XML-GB2312网页编码的处理方法

    报的错误:encoding error : input conversion failed due to input error, bytes  I/O error : encoder error 1 ...

  4. Mysql高手系列 - 第11篇:深入了解连接查询及原理

    这是Mysql系列第11篇. 环境:mysql5.7.25,cmd命令中进行演示. 当我们查询的数据来源于多张表的时候,我们需要用到连接查询,连接查询使用率非常高,希望大家都务必掌握. 本文内容 笛卡 ...

  5. JVM垃圾回收?看这一篇就够了!

    深入理解JVM垃圾回收机制 1.垃圾回收需要解决的问题及解决的办法总览 1.如何判定对象为垃圾对象 引用计数法 可达性分析法 2.如何回收 回收策略 标记-清除算法 复制算法 标记-整理算法 分带收集 ...

  6. Linux 笔记 - 第十三章 Linux 系统日常管理之(一)系统状态监控

    博客地址:http://www.moonxy.com 一.前言 如果你是一名 Linux 运维人员,最主要的工作是优化系统配置,使应用在系统上以最优的状态运行.系统运行状态主要包括:系统负载.内存状态 ...

  7. Nginx 日志文件 access_log详解及日志分割

    Module ngx_http_log_module nginx 日志相关指令主要有两条, 一条是log_format,用来设置日志格式,另外一条是access_log,用来指定日志文件的存放路径.格 ...

  8. 关于SP优化

    SET STATISTICS PROFILE ON;SET STATISTICS TIME ON;SET STATISTICS IO ON;--打开三个开关SET STATISTICS PROFILE ...

  9. Vue基础项目配置

    一,使用Vuejs搭建项目需要一些基础配置,这样能使的编程过程事半功倍 1.首先下载nodejs,然后使用nodejs使用NPM命令下载VueCli3.0以上的Vue脚手架.通过脚手架可以使用Vue  ...

  10. Hadoop核心组件之MapReduce

    MapReduce概述 Google MapReduce的克隆版本 优点:海量数据的离线处理,易开发,易运行 缺点:实时流式计算 Hadoop MapReduce是一个软件框架,用于轻松编写应用程序, ...