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 ...
随机推荐
- Springboot三层架构
control调用service调用dao
- Suffix Tree(后缀树)
这篇简单的谈谈后缀树原理及实现. 如前缀树原理一般,后缀trie树是将字符串的每个后缀使用trie树的算法来构造.例如banana的所有后缀: 0: banana 1: anana 2: nana 3 ...
- 详解python的字符编码问题
一:什么是编码 将明文转换为计算机可以识别的编码文本称为“编码”.反之从计算机可识别的编码文本转回为明文为“解码”. 那么什么是明文呢,首先我们从一段信息说起,消息以人们可以理解,易懂的表示存在,我们 ...
- linux动态监控dstat&&glances&&psutil&&bottle
安装dstat yum install dstat 安装glances yum install python-devel pip install glances 如果我们安装了 Bottle 这个 w ...
- 获取当前表中的最大自增id的下一个自增id值
SELECT auto_increment FROM information_schema.`TABLES` WHERE TABLE_SCHEMA='{$db_name}' AND TABLE_NAM ...
- Python 基础之面向对象之异常处理
一.认识异常 1.常用异常报错的错误类型 IndexError 索引超出序列的范围 KeyError 字典中查找一个不存在的关键字 Na ...
- flask-script扩展
在项目部署到线上时,指定端口号时,一般都不会在服务器上进行更改,所以使用flask-script就可以在Flask服务器启动时,通过命令行的方式传入参数,而不仅仅通过app.run()方法中传参.具体 ...
- python笔记心得
1.字典的映射 day=10# def get_sunday():# return 'Sunday'# def get_monday():# return 'monday'# def get_tues ...
- 1013 Battle Over Cities (25分) DFS | 并查集
1013 Battle Over Cities (25分) It is vitally important to have all the cities connected by highways ...
- IP show
1. 查看本机公网IP 1.1 curl ifconfig.me 1.2 ipinfo.io 1.3 test-ipv6.com 1.4 more 2. 查看本机IP,host 2.1 hostnam ...