当前位置:网站首页>0双指针 LeetCode844. 比较含退格的字符串
0双指针 LeetCode844. 比较含退格的字符串
2022-07-23 05:45:00 【18阿鲁】
分析
从后先前遍历,用time记录遇到#的次数,若Time > 0 或者当前是#则跳过,直到不满足上述条件,然后取比较两个字符串的字符是否是相同的
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;
}
}
```
边栏推荐
- 3.2daydayup draw inferences from one instance: three days of fishing and two days of net learning
- Vs attribute configuration related knowledge
- 博客搭建二:NexT主题相关设置beta
- Tencent cloud client command line tool tccli main process analysis
- 用单向链表实现 队列
- Anonymous upper computer V7 waveform display
- 剑*offer04 重建二叉树
- 常见的排序—交换排序
- Prometheus
- Questions and answers of basic principles of steel structure
猜你喜欢
![[physical layer of CAN bus] 1. Content sharing of can/canfd sampling points](/img/e4/0b709a6ed5e639a75e0506f6eac9fd.png)
[physical layer of CAN bus] 1. Content sharing of can/canfd sampling points

【Autosar DEM 四.Event Memory】

【AUTOSAR CanDrive 1.学习CanDrive的功能和结构】

C language small project - student achievement management system

5.4 Pyinstaller库安装与使用

博客搭建二:NexT主题相关设置beta

5.4 installation and use of pyinstaller Library

常见排序--归并排序(递归和非递归)+计数排序

Implementation of heap and heap sorting

C语言数据库:详细的说明用学生管理系统了解数据库的操作,简单易懂。
随机推荐
URL查询参数编码问题(golang)
求矩阵的鞍点及其对应的下标。
Unity在URP管线下使用TriLib插件加载模型材质不正确的问题
Common sorting method - Select Sorting
*offer--2
刷题笔记:二叉树的中序遍历(三种解法-递归,迭代,Morris)
Three versions and optimization of quick sorting by interval -- friends may not know it
剑*offer—— 链表逆序
The CUDA version of pytorch installed by anconda is inconsistent with the CUDA version of the system
[learning summary]
Mutual implementation of queue and heap (pure C implementation)
(1)ASIO
Review of basic principles of steel structure
Dicom开源工具库
C语言小项目——学生成绩管理系统
Navicat for MySQL 安装教程
TCP的粘包问题代码说明
Blog building six: the method of binding your own domain name
SCI审稿过程中的几种状态
socket基础知识以及各种使用场景