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 ...
随机推荐
- Cisco AP-Mobility Express基础
Part I 介绍 1.1基本概况 Cisco Mobility Express这个名词出现在Cisco “8”系列的AP上,例如现在的AP1852,AP2802,AP3802等都是Mobility ...
- ECMAScript 6 和数组的新功能
Array. @@iterator 返回一个包含数组键值对的迭代器对象,可以通过同步调用得到数组元素的键值对 copyWithin 复制数组中一系列元素到同一数组指定的起始位置 entries 返回包 ...
- WPS/office使用技巧系列
一 WPS中如果要对比2个文档,不想以标签形式打开而是以多窗口形式,该怎么操作? 点击WPS左上角的蓝色或绿色框-->选项->->视图->勾选在任务栏中显示所有窗口,恢复书签模 ...
- 研发2nm芯片,台积电如何做到天下第一?
日前,台积电宣布,正式启动2nm芯片工艺的研发,工厂将会设置在台湾新竹的南方科技园,预计2024年投入量产,发言人称:2nm工艺是一个重要节点,目标是比3nm制程缩小23%.科技先锋总会打脸分析专家, ...
- ZooKeeper 相关知识
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/zhang123456456/articl ...
- 修改html内联样式的方法
问题:如下图弹出页面操作不了 分析:审查元素,发现是内联元素样式z-index:19891015导致的,修改内联元素样式z-index:0发现可以操作了 解决方法:内联样式优先级高,再引入css覆盖样 ...
- 定时任务--mysql数据库备份
vim /home/back.sh #!/bin/bash USER="******" PASSWORD="******" DATABASE="*** ...
- JavaScript - 编译性还是解释性?
疑问 在JS的变量和声明式函数的提升看到了"预编译/预处理/预解释"中"预编译"这个字眼,产生了一个疑问:JS是熟知的解释性语言,但JS能被编译吗? 参考 ht ...
- Steam 游戏 《The Vagrant(流浪者)》修改器制作-[先使用CE写,之后有时间的话改用CheatMaker](2020年寒假小目标08)
日期:2020.02.07 博客期:146 星期五 [温馨提示]: 只是想要修改器的网友,可以直接点击此链接下载: 只是想拿CT文件的网友,可以直接点击此链接下载: 没有博客园账号的网友,可以将页面下 ...
- css3内外阴影同时显示
内外阴影同时显示: box-shadow: 0px 0px 0.4rem rgba(255,255,255,0.5) inset,0px 0px 0.7rem rgba(185,119,143,0.9 ...