LeetCode_844-Backspace String Compare
输入两个字符串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的更多相关文章
- 【Leetcode_easy】844. Backspace String Compare
problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...
- [LeetCode] Backspace String Compare 退格字符串比较
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- [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 ...
- LeetCode - Backspace String Compare
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- 844. Backspace String Compare判断删除后的结果是否相等
[抄题]: Given two strings S and T, return if they are equal when both are typed into empty text editor ...
- 844. Backspace String Compare
class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...
- 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 ...
- [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 ...
- leetcode844 Backspace String Compare
""" Given two strings S and T, return if they are equal when both are typed into empt ...
- C#LeetCode刷题之#844-比较含退格的字符串(Backspace String Compare)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4030 访问. 给定 S 和 T 两个字符串,当它们分别被输入到空 ...
随机推荐
- Erlang模块file翻译
模块摘要 文件接口模块 描述 模块file提供了文件系统的接口. 在具有线程支持的操作系统上,可以让文件操作以其自己的线程执行,从而允许其他Erlang进程与文件操作并行地 ...
- bzoj2141_排队
题意 给定\(n\)个数,每次交换两个数,输出交换后的逆序数. 分析 交换两个数只会影响到对应区间内的逆序数,具体为减少区间\([l+1,r-1]\)中比\(a[r]\)大的数的个数,增加比\(a[r ...
- 033 模块4-PyInstaller库的使用
目录 一.PyInstaller库基本介绍 1.1 PyInstaller库概述 1.2 pip的使用 1.3 pip install pyinstaller (cmd命令行) 二.PyInstall ...
- Java深拷贝与序列化
对基本类型的变量进行拷贝非常简单,直接赋值给另外一个对象即可: int b = 50; int a = b; // 基本类型赋值 对于引用类型的变量(例如 String),情况稍微复杂一些,因为直接等 ...
- .Net基础篇_学习笔记_第五天_流程控制do-while循环
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 泛型接口、JAVA API、包装类
泛型接口就是拥有一个或多个类型参数的接口 语法: public interface 接口名<类型形参>{ 方法名(类型形参 类型形参实例); } 示例: public interface ...
- Apache Commons Collections 反序列化详细分析学习总结
0x01.环境准备: Apache Commons Collections 3.1版本,下载链接参考: https://www.secfree.com/a/231.html jd jui地址(将jar ...
- 初识数据库(MySql)
一.简介 1.MySql是关系型数据库. 2.是一种开放源码软件, 3.是一种关联数据库管理系统. 4.服务器工作于客户端/服务端模式之下,或者是嵌入系统中. 数据库管理软件分类: 分两大类: 关系型 ...
- MySQL中常用到的关于时间的SQL
-- 今天 SELECT DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00') AS dayStart;SELECT DATE_FORMAT(NOW(),'%Y-%m-%d 2 ...
- MYSQL增删改查添加外键
给商品表(从表)添加一个外键 ALTER TABLE product ADD CONSTRAINT FK_cno FOREIGN KEY(cno) REFERENCES category(cid 从 ...