[LeetCode&Python] Problem 844. 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".
Note:
1 <= S.length <= 200
1 <= T.length <= 200
S
andT
only contain lowercase letters and'#'
characters.
Follow up:
- Can you solve it in
O(N)
time andO(1)
space?
class Solution(object):
def backspaceCompare(self, S, T):
"""
:type S: str
:type T: str
:rtype: bool
"""
Sr=[]
i=0
while i<len(S):
if S[i]=='#':
if Sr:
Sr.pop()
else:
Sr.append(S[i])
i+=1 Tr=[]
i=0
while i<len(T):
if T[i]=='#':
if Tr:
Tr.pop()
else:
Tr.append(T[i])
i+=1 return Tr==Sr
[LeetCode&Python] Problem 844. Backspace String Compare的更多相关文章
- 【Leetcode_easy】844. Backspace String Compare
problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...
- 【LeetCode】844. Backspace String Compare 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串切片 栈 日期 题目地址:https://le ...
- [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 ...
- 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&Python] Problem 541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...
- [LeetCode&Python] Problem 796. Rotate String
We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost ...
- [LeetCode&Python] Problem 606. Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...
- [LeetCode] Backspace String Compare 退格字符串比较
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
随机推荐
- 修改SS配置文件使其同时支持IPV4和IPV6网络
将/etc/shadowsocks-libev/config.json文件中的 "server":"0.0.0.0", 修改为: "server&qu ...
- react中使用antd遇到的问题
1.less使用报错 less配置修改一般都是1个修改1个增加 test: /\.(css|less)$/, // 修改 // 增加 { loader: require.resolve('less-l ...
- Linux中通过Socket文件描述符寻找连接状态介绍
针对下文的总结:socket是一种文件描述符 进程的打开文件描述符表 Linux的三个系统调用:open,socket,pipe 返回的都是一个描述符.不同的进程中,他们返回的描述符可以相同.那么,在 ...
- 使用ByteArrayOutputStream解决IO乱码问题的踩坑记录
经过:今天在用s3接口做ceph储存的时候,要实现一个io下载的接口.需要把InputStream转成byte[],一开始,是的写法是这样的: byte[] buf = new byte[(int) ...
- 问题处理:Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
进入rails 文件夹, terminal输入rails console报告❌. 类似下面的 Running via Spring preloader Traceback (most recent c ...
- 精析python中的装饰器、生成器
装饰器: 在编程时,要遵循一个原则,就是开放-封闭原则. 在不破坏原函数的情况下,要想对原函数进行一些修饰,那么这里就要用到装饰器. 例如:你完成了一些用函数写成的项目,此时公司正在年度考核,你需要给 ...
- mybatis-generator自动生成代码工具
1.在项目的配置文件中放入配置文件mybatis-generator-config.xml 根据情况修改下配置 <?xml version="1.0" encoding= ...
- The C compiler identification is unknown解决办法
环境:VS2015,CMake3.12.0. 问题一: 解决办法:下载并安装Windows SDK version 8.1. 问题二: 解决办法:这个问题百度了半天也没找到合适的办法,好多博客都是复制 ...
- canvas绘图基础
<canvas>元素是HTML5中的绘图元素,通过定义一个画布区域,然后使用javascript动态地在这个区域里面绘制图形,对于2D和3D图形都可以绘制,我们将其分成2D上下文和WebG ...
- laravel5.5 调用系统自带登陆认证auth
1执行命令 php artisan make:auth 2 编辑文件 config/auth guardes 'admin' => [ 'driver' => 'session', 'pr ...