当前位置:网站首页>0 double pointer leetcode844. Compare strings with backspace
0 double pointer leetcode844. Compare strings with backspace
2022-07-23 12:56:00 【18 ARU】
analysis
Traverse from back to front , use time Record encountered # The number of times , if Time > 0 Or is it currently # Then skip , Until the above conditions are not met , Then compare whether the characters of the two strings are the same
class Solution {
public boolean backspaceCompare(String s, String t) {
int i = s.length() - 1, j = t.length() - 1;
int times1 = 0, times2 = 0;
while (i >= 0 || j >= 0) {
while (i >= 0 && (s.charAt(i) == '#' || times1 > 0)) {
if (s.charAt(i) == '#') {
times1++;
} else {
times1--;
}
i--;
}
while (j >= 0 && (t.charAt(j) == '#' || times2 > 0)) {
if (t.charAt(j) == '#') {
times2++;
} else {
times2--;
}
j--;
}
if (i >= 0 && j >= 0 && (s.charAt(i) != t.charAt(j))) {
return false;
}
i--;
j--;
}
if (i == j) {
return true;
}
return false;
}
}
```
边栏推荐
- 学习日记——(路由与交换技术)DHCP(动态主机配置协议)
- DHCP second experiment
- jenkins部署
- In depth analysis of replication in redis
- Unity3d:ugui source code eventsystem input system FAQ
- Unity mouse controls camera drag, rotation and zoom (simulation editor camera function)
- 静态路由配置实例学习记录
- PDF在线预览,pdf.js的使用
- How to write a web page with a common text editor
- Unity shader missing problem
猜你喜欢

学习日记(路由与交换技术)——浮动静态路由和缺省路由

C custom queue set

Unity3d+moba+ skill indicator (II)

@Requiredargsconstructor annotation use

Unity3d:ugui, UI and special effect particle level, bakemesh above 2018.2, particles between two images and in Scrollview

Hcip --- OSPF details

OSPF comprehensive experiment in hcip-mgre environment

单臂路由配置实例学习记录

DHCP原理与配置

MySQL performance optimization, index optimization
随机推荐
写一个可执行文件依赖.so的测试用例
学习日记(路由与交换技术)——浮动静态路由和缺省路由
RK3588编译问题集
PDF在线预览,pdf.js的使用
htpasswd作用
Nas里搭建Frpc客户端【超级无脑】
Hcip-hcia knowledge review (II)
记一次日志文件IO系统的设计心得
C # custom stack
深度优先找出图中顶点U到顶点V的所有简单路径
LSM-tree(Log Structured-Merge Tree)的理解
PDF Online preview, use of pdf.js
Eth-Trunk 配置实例学习记录
Gameframework:resource loading, resource loading, dependency loading, task pool, object pool, reference count
Learning diary - (routing and switching technology) DHCP (Dynamic Host Configuration Protocol)
Openssl自行签证流程概述
PostgreSQL k8s部署模板
Pod 拓扑约束
Telnet 配置实例学习记录
post表单提交数据限制