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 ...
随机推荐
- UNL/EVE关联putty和wireshark
这里默认UNL已经安装完毕,然后启动虚拟机启动UNL. 在浏览器输入http://192.168.1.199/ 进入UNL.然后简单的搭建一个拓扑: 这里只讲R1和ASA开启,先来配置Telnet功能 ...
- mybatis源码探索笔记-1(构建SqlSessionFactory)
前言 mybatis是目前进行java开发 dao层较为流行的框架,其较为轻量级的特性,避免了类似hibernate的重量级封装.同时将sql的查询与与实现分离,实现了sql的解耦.学习成本较hibe ...
- 研发2nm芯片,台积电如何做到天下第一?
日前,台积电宣布,正式启动2nm芯片工艺的研发,工厂将会设置在台湾新竹的南方科技园,预计2024年投入量产,发言人称:2nm工艺是一个重要节点,目标是比3nm制程缩小23%.科技先锋总会打脸分析专家, ...
- 解决CentOS下boost安装后不能使用的问题
先说一说整个经历. 因为之前没有注意到gcc4.8.5比较旧,就已经安装好boost了,当时已经可以使用了,后来发现gcc太老了,一些软件安装需要比较新的gcc支持,所以决定升级gcc,结果boost ...
- idea修改项目编码
- sarima模型
以下内容引自:https://blog.csdn.net/qifeidemumu/article/details/88782550 使用“网格搜索”来迭代地探索参数的不同组合. 对于参数的每个组合,我 ...
- 后台框架 FastAdmin V1.0.0.20200228 发布,为疫情防控作贡献
后台框架 FastAdmin V1.0.0.20200228 发布,为疫情防控作贡献 https://www.oschina.net/news/113694/fastadmin-1-20200228- ...
- Java基础知识笔记第三章:运算符表达式语句
算术运算符与表达式 操作符 描述 例子 + 加法 - 相加运算符两侧的值 A + B 等于 30 - 减法 - 左操作数减去右操作数 A – B 等于 -10 * 乘法 - 相乘操作符两侧的值 A * ...
- Apache+Php+Mysql配置
软件工具:(下载时注意下载相应版本,不同版本安装细节可能会有差异!!) 1>httpd-2.4.18-win64-VC14.zip 下载地址: http://www.apachelounge.c ...
- Python学习笔记005
if if == : xxxx elif : xxxx else: xxxx 输入字符串 input() 字符串转数值 int() 数值转字符串 str() 输出 print() ...