输入两个字符串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. 数论 Day 13

    数论_CRT(中国剩余定理)& Lucas (卢卡斯定理) 前言 又是一脸懵逼的一天. 正文 按照道理来说,我们应该先做一个介绍. 中国剩余定理 中国剩余定理,Chinese Remainde ...

  2. Spring boot运行原理-自定义自动配置类

    在前面SpringBoot的文章中介绍了SpringBoot的基本配置,今天我们将给大家讲一讲SpringBoot的运行原理,然后根据原理我们自定义一个starter pom. 本章对于后续继续学习S ...

  3. 行内元素有哪些?块级元素有哪些?空(void)元素有哪些?

    CSS规范规定,每个元素都有display属性,确定该元素的类型.每个元素都有默认的display值,如div的display默认值为“block”,则为“块级”元素:span默认display属性值 ...

  4. Apollo源码解析-搭建调试环境

    准备工作 本地运行时环境 JDK :1.8+ MySQL :5.6.5+ Maven :3.6.1 IDE :IntelliJ IDEA Apollo的表结构对timestamp使用了多个defaul ...

  5. spring scope prototype与singleton区别

    1.singleton作用域  当一个bean的作用域设置为singleton, 那么Spring IOC容器中只会存在一个共享的bean实例,并且所有对bean的请求,只要id与该bean定义相匹配 ...

  6. [Spark] 02 - Practice Spark

    开发环境 教学视频:Spark的环境搭建,需安装配置环境:Java, Hadoop 环境配置:玩转大数据分析!Spark2.X+Python 精华实战课程(免费)[其实只是环境搭建] 进入pyspar ...

  7. C# 代码往oracle数据库添加datetime格式列

    C# 代码往oracle数据库添加datetime格式列时,不需要在insert语句中为datetime类型使用to_date函数

  8. pathlib模块

    一.pathlib库官方定义 pathlib 是Python内置库,Python 文档给它的定义是 Object-oriented filesystem paths(面向对象的文件系统路径).path ...

  9. 转:ext的xtype值

    基本组件: xtype Class 描述 button Ext.Button 按钮 splitbutton Ext.SplitButton 带下拉菜单的按钮 cycle Ext.CycleButton ...

  10. 浅谈HDFS(二)之NameNode与SecondaryNameNode

    NN与2NN工作机制 思考:NameNode中的元数据是存储在哪里的? 假设存储在NameNode节点的硬盘中,因为经常需要随机访问和响应客户请求,必然效率太低,所以是存储在内存中的 但是,如果存储在 ...