"""
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

最新文章

  1. 《2016ThoughtWorks技术雷达峰会----雷达新趋势》
  2. ftp列表错误或长城宽带连不上ftp的解决方法
  3. IOS开发 程序关闭状态接通知
  4. Mac下修改环境变量
  5. css清除浮动的处理方法
  6. PADS Layout 使用
  7. git终端提示符
  8. 51单片机C语言学习笔记6:51单片机C语言头文件及其使用
  9. 数塔(dp)
  10. Flex中神奇的快速辅助 Ctrl+1
  11. IT实用技术资源整理
  12. P1164 小A点菜
  13. [ci]jenkins-slave-ssh docker容器化-用户名密码
  14. 【Ruby】【目录 & 引用 & 文件 】
  15. Writing and playing with custom Terraform Providers
  16. 初始MapReduce
  17. 转 configure: error: Cannot find ldap libraries in /usr/lib 解决办法
  18. egret list不显示问题
  19. nacicat premium 快捷键
  20. Vi 学习 笔记

热门文章

  1. Cisco AP-胖瘦AP的转换
  2. APDL获取节点和单元的结果
  3. SpringMVC 配置文件详解
  4. django-实现登录短信验证
  5. 番外篇!全球首个微信应用号开发教程!小程序 DEMO 视频奉上!
  6. kubernetes从入门到放弃(二)
  7. 【已解决】iOS11使用MJRefresh上拉加载结束tableView闪动、跳动的问题
  8. Airless Pump Bottle For The Rise Of Cosmetic Packaging Solutions
  9. PAT T1017 The Best Peak Shape
  10. Spring Boot 2.x教程-Thymeleaf 原理是什么