当前位置:网站首页>双指针 | 844. 比较含退格的字符串
双指针 | 844. 比较含退格的字符串
2022-06-10 02:02:00 【lee2813】
一、题目

二、题解
解法一:得到退格后的字符串,然后两两比较
解法二:双指针法
定义快指针和慢指针。快指针用于依次遍历,满指针用于存有效值并在原数组的基础上划分有效值边界。
三、代码
class Solution {
public:
bool backspaceCompare(string S, string T) {
return build(S) == build(T);
}
string build(string str) {
int slow = 0;
int fast = 0;
for(; fast < str.size(); fast++ ){
if(str[fast] != '#'){
str[slow] = str[fast];
slow++;
}else if(slow > 0){
slow--;
}
}
return str.substr(0,slow);
}
};
边栏推荐
- Simulated 100 questions and answers of the third batch of Guangdong Provincial Safety Officer a certificate (principal) examination in 2022
- 大学生 生活小技巧:利用插件(Tampermonkey )学习网课 | 查题
- Stepper motor summary
- Electron桌面端开发(能力、如何打包、优势)
- 【WIN】浏览器打不开网页出现DNS_PROBE_FINISHED_NO_INTERNET
- Low code analysis and inventory: two misunderstandings need to be avoided in the application of low code in the banking industry
- 不会编程也能亲手编写一个桌面数字小时钟程序,仅3步轻松实现
- Hongmeng tablist cooperates with fraction to achieve top switching effect
- kubelet启动一个Pod CRI、CNI、CSI 起作用的顺序
- With all due respect: programmers spend most of their time not writing code, but...
猜你喜欢

机智云轻网关服务,提升生产管理效率

Leetcode 700: search in binary search tree

2. Introduction to naturallanguageprocessing

Esp32-c3 single fire wire intelligent switch enables intelligent upgrading of traditional switch

What does the server stop responding mean and how to troubleshoot it?

Catering e-procurement scheme: procurement cycle management, saving 30% of the cost

Inftnews | when the meta universe is going on: how are those big Internet companies planning their layout?

mysql路径添加至系统环境变量(win10)

虚幻引擎UE4.26源码剖析之环境配置与初编译

When the MySQL service is started during initialization, it shows that net is neither an internal or external command nor a runnable program. How to solve this problem? This is the same as net Exe mis
随机推荐
OpenSUSE add boot entry
Smart cloud light gateway service to improve production management efficiency
Detailed billing information tables of cptevents and drgcodes (XIII)
Inftnews | the future of NFT in Web3 economy
Esp32-c3 single fire wire intelligent switch enables intelligent upgrading of traditional switch
起薪1800,三年来手头只积攒一万块,裸辞奔赴一线城市月薪达3万
Use primecache to speed up your computer!
Notepad++ advanced method of adding right-click menu
1、pytorch入门
Hongmeng hilog log printing tips
Leetcode 700: search in binary search tree
[group planning final review iv] input / output system
SSM框架整合-搭建简单账号登录系统
Apache POI learning notes - Excel
2022年上海市安全员C证考试模拟100题及模拟考试
51 single chip microcomputer learning record (VI) IIC, ADC part
2022 Shanghai safety officer C certificate examination simulation 100 questions and simulation examination
Eight honors and eight disgraces of programmers' daily development
步进电机总结
MySQL table management (file)