leetcode844 Backspace String Compare
"""
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
leetcode844 Backspace String Compare的更多相关文章
- leetcode-844 Backspace String Compare
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- Leetcode844.Backspace String Compare比较含退格的字符串
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果. # 代表退格字符. 示例 1: 输入:S = "ab#c", T = " ...
- 【Leetcode_easy】844. Backspace String Compare
problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...
- [Swift]LeetCode844. 比较含退格的字符串 | Backspace String Compare
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- [LeetCode] Backspace String Compare 退格字符串比较
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- LeetCode - Backspace String Compare
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- 844. Backspace String Compare判断删除后的结果是否相等
[抄题]: Given two strings S and T, return if they are equal when both are typed into empty text editor ...
- 844. Backspace String Compare
class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...
- [LeetCode] 844. Backspace String Compare 退格字符串比较
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
随机推荐
- Nexus-VDC(Virtual Device Context)
VDC实际上是将一台物理的Nexus7K设备虚拟为多个逻辑的VDC设备,该术语叫做VDC(Virtual Device Context),该虚拟技术实际上是在一个物理设备架构和内核上运行多个VDC,已 ...
- web打开本地文件并读取内容
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 牛客-Y 老师的井字窗
链接:https://ac.nowcoder.com/acm/contest/3667/B来源:牛客网 Y 老师因为贫穷破费(应该是去买乐高玩具了),现在只能将他镀金的门窗变卖换钱了,但这样就不能抵御 ...
- Update(Stage4):spark_rdd算子:第2节 RDD_action算子_分区_缓存:算子和分区
一.reduce和reduceByKey: 二.:RDD 的算子总结 RDD 的算子大部分都会生成一些专用的 RDD map, flatMap, filter 等算子会生成 MapPartitions ...
- I/O-<File实例>
File n=new File("D:\2016.txt"); System.out.println("文件是否存在"+n.exists()); System. ...
- PB specified database is invalid
拷贝资料库到其他机器,可以重新配置ODBC ,如果还是报错,建议删除log .
- lable 语句
var is = 20; loop: while(is > 10){ console.log(is); if(is % 7 == 0){ break loop; } is --; } 结果: b ...
- JavaScript图形实例:线段构图
在“JavaScript图形实例:四瓣花型图案”和“JavaScript图形实例:蝴蝶结图案”中,我们绘制图形时,主要采用的方法是先根据给定的曲线参数方程计算出两点坐标,然后将两点用线段连接起来,线段 ...
- Redis数据库在windows系统下的安装及使用
1.下载 Redis官方是不支持windows的,但是Microsoft Open Tech group 在 GitHub上开发了一个Win64的版本,下载地址:https://github.com/ ...
- 腾讯云 docker 镜像 dotnet/core sdk aspnet
ccr.ccs.tencentyun.com/mcr.microsoft.com/dotnetcoresdk = mcr.microsoft.com/dotnet/core/sdk => 3 ...