[抄题]:

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

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:以为要用stack:可是应该考虑这个占的空间比较大

[英文数据结构或算法,为什么不用别的数据结构或算法]:

统计numOfBlankspaces的个数,然后看i j是否同时倒数到1

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

统计numOfBlankspaces的个数,然后看i j是否同时倒数到1

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

[潜台词] :

class Solution {
public boolean backspaceCompare(String S, String T) {
for (int i = S.length() - 1, j = T.length() - 1; ; i--, j--) {
for (int numOfBlankspaces = 0; i >= 0 && (numOfBlankspaces > 0 || S.charAt(i) == '#'); i--) {
numOfBlankspaces = S.charAt(i) == '#' ? numOfBlankspaces + 1 : numOfBlankspaces - 1;
}
for (int numOfBlankspaces = 0; j >= 0 && (numOfBlankspaces > 0 || T.charAt(j) == '#'); j--) {
numOfBlankspaces = T.charAt(j) == '#' ? numOfBlankspaces + 1 : numOfBlankspaces - 1;
}
if (i == -1 || j == -1 || S.charAt(i) != T.charAt(j)) return (i == -1) && (j == -1);
}
}
}

844. Backspace String Compare判断删除后的结果是否相等的更多相关文章

  1. 【Leetcode_easy】844. Backspace String Compare

    problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...

  2. [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 ...

  3. 844. Backspace String Compare

    class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...

  4. 【LeetCode】844. Backspace String Compare 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串切片 栈 日期 题目地址:https://le ...

  5. [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. # m ...

  6. [LeetCode] Backspace String Compare 退格字符串比较

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  7. [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 ...

  8. LeetCode算法题-Backspace String Compare(Java实现)

    这是悦乐书的第327次更新,第350篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第197题(顺位题号是844).给定两个字符串S和T,如果两个字符串都输入到空文本编辑器 ...

  9. C#LeetCode刷题之#844-比较含退格的字符串​​​​​​​(Backspace String Compare)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4030 访问. 给定 S 和 T 两个字符串,当它们分别被输入到空 ...

随机推荐

  1. Java学习路线(转)

    原文:http://www.hollischuang.com/archives/489 一.基础篇 1.1 JVM 1.1.1. Java内存模型,Java内存管理,Java堆和栈,垃圾回收 http ...

  2. 16.Set、List、Queue集合;Map.md

    目录 1.Set 1.2HashSet TreeSet 2.List 2.1ArrayList 2.1.1ArrayList和Vector的区别 2.2LinkedList 3.Queue 4.各种线 ...

  3. C# 图像处理:复制屏幕到内存中,拷屏操作

    /// <summary> /// 复制屏幕到内存中 /// </summary> /// <returns>返回内存流</returns> publi ...

  4. Android Monkey: “No activities found to run, monkey aborted”错误原因

    用monkey测试app时,输入命令adb shell monkey -p  com.example.test -v -500 发现报错, 错误输入: :Monkey: seed=13 count=5 ...

  5. GBDT+Lr

    https://blog.csdn.net/shine19930820/article/details/71713680 http://scikit-learn.org/stable/auto_exa ...

  6. myEclips 中的项目复制重命名

    现在有个项目Pj ,要复制一个Pu 一,退出 myEclips. 二,找到Pj备份一份到其他目录. 三,进入myEclips,F2修改项目名Pj至Pu. 四,将备份拷贝回原目录. 五,将Pj重新引进m ...

  7. 《深入理解JAVA虚拟机》----------第三章 垃圾收集器与内存分配策略,笔记(下)

    1.垃圾收集器 1.1 Serial收集器 这个收集器是一个单线程的收集器,它在进行垃圾收集时,必须暂停其他所有的工作线程. 它是虚拟机运行在Client模式下的默认新生代收集器,它简单而高效. 1. ...

  8. kubectl windows

    https://storage.googleapis.com/kubernetes-release/release/v1.10.3/bin/windows/amd64/kubectl.exe

  9. elastastic search

    curl -X PUT "10.97.184.40:9200/logstash-2015.05.18" -H 'Content-Type: application/json' -d ...

  10. 输入框状态禁止enter键提交表单

    1:页面中如果存在input输入框和submit提交按钮时,默认按enter键会提交表单,如果我现在在做查询操作,一不小心按了enter键就会有提交表单的操作,这样显然是不合理的,所以我们要禁止按en ...