leetcode844 Backspace String Compare
2024-10-08 15:52:02
"""
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.
Example 1:
Input: S = "ab#c", T = "ad#c"
Output: true
Explanation: Both S and T become "ac".
Example 2:
Input: S = "ab##", T = "c#d#"
Output: true
Explanation: Both S and T become "".
Example 3:
Input: S = "a##c", T = "#a#c"
Output: true
Explanation: Both S and T become "c".
Example 4:
Input: S = "a#c", T = "b"
Output: false
Explanation: S becomes "c" while T becomes "b".
"""
"""
简单题通过
"""
class Solution:
def backspaceCompare(self, S, T):
"""
:type S: str
:type T: str
:rtype: bool
"""
return self._back(S) == self._back(T)
def _back(self, string):
stack = []
for i in range(len(string)):
if string[i] == '#':
if stack: #这里重要,需要判断stack不为空,对于这种[#a#c]输入
stack.pop()
continue
stack.append(string[i])
return stack
最新文章
- 《2016ThoughtWorks技术雷达峰会----雷达新趋势》
- ftp列表错误或长城宽带连不上ftp的解决方法
- IOS开发 程序关闭状态接通知
- Mac下修改环境变量
- css清除浮动的处理方法
- PADS Layout 使用
- git终端提示符
- 51单片机C语言学习笔记6:51单片机C语言头文件及其使用
- 数塔(dp)
- Flex中神奇的快速辅助 Ctrl+1
- IT实用技术资源整理
- P1164 小A点菜
- [ci]jenkins-slave-ssh docker容器化-用户名密码
- 【Ruby】【目录 &; 引用 &; 文件 】
- Writing and playing with custom Terraform Providers
- 初始MapReduce
- 转 configure: error: Cannot find ldap libraries in /usr/lib 解决办法
- egret list不显示问题
- nacicat premium 快捷键
- Vi 学习 笔记
热门文章
- Cisco AP-胖瘦AP的转换
- APDL获取节点和单元的结果
- SpringMVC 配置文件详解
- django-实现登录短信验证
- 番外篇!全球首个微信应用号开发教程!小程序 DEMO 视频奉上!
- kubernetes从入门到放弃(二)
- 【已解决】iOS11使用MJRefresh上拉加载结束tableView闪动、跳动的问题
- Airless Pump Bottle For The Rise Of Cosmetic Packaging Solutions
- PAT T1017 The Best Peak Shape
- Spring Boot 2.x教程-Thymeleaf 原理是什么