当前位置:网站首页>844. 比较含退格的字符串
844. 比较含退格的字符串
2022-06-11 08:55:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:844. 比较含退格的字符串
描述:给定 s 和 t 两个字符串,当它们分别被输入到空白的文本编辑器后,如果两者相等,返回 true 。# 代表退格字符。
注意:如果对空文本输入退格字符,文本继续为空。
解题思路
1、遇见#就弹出栈顶;
2、原本是想用栈,结果看了官方答案,卧槽,原来字符串自己就能出栈入栈,好家伙,学到了。
3、字符串本身入栈是push_back(),出栈是pop_back();
原代码##
class Solution {
public:
string build(string str) {
string ret = "";
for (int i = 0; i < str.size(); ++i) {
if (str[i] != '#') {
ret.push_back(str[i]);
} else if (!ret.empty()) {
ret.pop_back();
}
}
return ret;
}
bool backspaceCompare(string s, string t) {
return build(s) == build(t);
}
};
边栏推荐
- Are the test methods of CMVSS TSD No. 302 and 49 CFR 571.302 the same
- Screaming Frog Log File Analyser 中文版安装教程
- leetcode - 460. LFU 缓存
- Codeworks round 680 div2
- 显示器要申请BS 476-7 怎么送样?跟显示屏一样吗
- What software is required to process raw format images?
- leetcode - 460. LFU cache
- 端口占用问题,10000端口
- typescript高阶特性一 —— 合并类型(&)
- Introduction to knowledge atlas -- yedda annotation
猜你喜欢

B+ super tree helps you know the underlying structure of MySQL

Award winning survey | how Apache pulsar lived in 2022, you the final say

Matlab学习8-图像处理之线性与非线性锐化滤波、非线性平滑滤波

Sword finger offer 62 The last remaining number in the circle

leetcode - 230. The k-th smallest element in a binary search tree

SAP ODATA 开发教程

Sword finger offer 10- ii Frog jumping on steps

Zipkin入门
![[Clickhouse column] user initialization of new library role](/img/00/a11fb1a8e38ed4e0634839160c8ead.png)
[Clickhouse column] user initialization of new library role

c语言打印心形
随机推荐
MySQL核心点笔记
PVC plastic sheets BS 476-6 determination of flame propagation properties
M1 chip guide: M1, M1 pro, M1 Max and M1 ultra
TextView文本大小自动适配与TextView边距的去除
Screaming Frog Log File Analyser 中文版安装教程
补2:圆环回原点问题
【C语言-数据存储】数据在内存中是怎样存储的?
Type of SQL command (incomplete)
[node] NPM part
mysql高级特性篇,可以多看看,应付面试
Supplement 2: circle returning to origin
Codetop - sort odd ascending even descending linked list
光伏板怎么申请ASTM E108阻燃测试?
PHP uploading large files for more than 40 seconds server 500
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
PHP solves Chinese display garbled code
命名实体识别之CRF的实现方式
Complete ES6 questions
Android 面试笔录(精心整理篇)
SAP abap 数据类型与数据对象