LeetCode 844. Backspace String Compare

考点 难度
Simulation Easy
题目

Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

Note that after backspacing an empty text, the text will continue empty.

思路

用helper function把st转换成不带#的string,然后比较两个string。stack转换到string用的是String.valueOf(ans);

答案
public boolean backspaceCompare(String S, String T) {return build(S).equals(build(T));
}public String build(String S) {Stack<Character> ans = new Stack();for (char c: S.toCharArray()) {if (c != '#')ans.push(c);else if (!ans.empty())ans.pop();}return String.valueOf(ans);
}

LeetCode知识点总结 - 844相关推荐

  1. LeetCode知识点总结 - 884

    LeetCode 884. Uncommon Words from Two Sentences 考点 难度 Hash Table Easy 题目 A sentence is a string of s ...

  2. LeetCode知识点总结 - 868

    LeetCode 868. Binary Gap 考点 难度 Math Easy 题目 Given a positive integer n, find and return the longest ...

  3. LeetCode知识点总结 - 1413

    LeetCode 1413. Minimum Value to Get Positive Step by Step Sum 考点 难度 Prefix Sum Easy 题目 Given an arra ...

  4. LeetCode知识点总结 - 2073

    LeetCode 2073. Time Needed to Buy Tickets 考点 难度 Simulation Easy 题目 There are n people in a line queu ...

  5. LeetCode知识点总结 - 347

    LeetCode 347. Top K Frequent Elements 考点 难度 Array Medium 题目 Given an integer array nums and an integ ...

  6. LeetCode知识点总结 - 997

    LeetCode 997. Find the Town Judge 考点 难度 Hash Table Easy 题目 In a town, there are n people labeled fro ...

  7. LeetCode知识点总结 - 606

    LeetCode 606. Construct String from Binary Tree 考点 难度 String Easy 题目 Given the root of a binary tree ...

  8. LeetCode知识点总结 - 977

    LeetCode 977. Squares of a Sorted Array 考点 难度 Sorting Easy 题目 Given an integer array nums sorted in ...

  9. LeetCode知识点总结 - 377

    LeetCode 377. Combination Sum IV 考点 难度 DP Medium 题目 Given an array of distinct integers nums and a t ...

最新文章

  1. pytorch model.train() 开启batchnormalize 和 dropout model.eval() 则会关闭dropout
  2. RedHat linux服务器对外开放指定端口
  3. 《第13章 猜拳游戏》
  4. Maven集成指令总结
  5. mysql建库权限_mysql数据库用户权限及建库脚本
  6. python查看list_reverseiterator object中的内容
  7. NumPy Cookbook 带注释源码 三、掌握 NumPy 常用函数
  8. RFM模型的理解和python案例分析
  9. Colmap中depth_map部分的源码
  10. WPF在资源内嵌入字体
  11. 智商情商哪个重要_你认为哪个更重要,情商还是智商?为什么?
  12. android打鸭子代码,打鸭子安卓版
  13. 【Windows Tips】关闭 Windows Defender
  14. ai怎么让图片任意变形_ai文字怎么随意变形?ai文字变形技巧教程
  15. 微信公众号开发教程(序)
  16. English Learning - Day20 作业打卡 2022.12.26 周一
  17. 经典的排错过程 expected unqualified-id before string constant
  18. ARM 微处理器的数据类型
  19. JUC第六讲:ThreadLocal/InheritableThreadLocal详解/TTL-MDC日志上下文实践
  20. Spring Boot集成阿里云视频点播服务的过程记录

热门文章

  1. 计算机库网络不见了,在电脑中的库文件夹不见了的找回方法介绍
  2. 关于ios程序的后台运行
  3. R语言小白学习笔记12—概率分布
  4. PPT学习资源和实用技巧
  5. 简单两步搞定小米路由新增功能-DDNS
  6. sohc和vtec的关系
  7. Linux如何解压tar.xz文件
  8. 一个定时器生成多路PWM波形的原理和方法成都自动化开发
  9. 英文歌曲:A place nearby (天堂若比邻)
  10. 如何在不停机的情况下在Django中创建索引