LeetCode知识点总结 - 844
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把s
和t
转换成不带#
的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相关推荐
- LeetCode知识点总结 - 884
LeetCode 884. Uncommon Words from Two Sentences 考点 难度 Hash Table Easy 题目 A sentence is a string of s ...
- LeetCode知识点总结 - 868
LeetCode 868. Binary Gap 考点 难度 Math Easy 题目 Given a positive integer n, find and return the longest ...
- LeetCode知识点总结 - 1413
LeetCode 1413. Minimum Value to Get Positive Step by Step Sum 考点 难度 Prefix Sum Easy 题目 Given an arra ...
- LeetCode知识点总结 - 2073
LeetCode 2073. Time Needed to Buy Tickets 考点 难度 Simulation Easy 题目 There are n people in a line queu ...
- LeetCode知识点总结 - 347
LeetCode 347. Top K Frequent Elements 考点 难度 Array Medium 题目 Given an integer array nums and an integ ...
- LeetCode知识点总结 - 997
LeetCode 997. Find the Town Judge 考点 难度 Hash Table Easy 题目 In a town, there are n people labeled fro ...
- LeetCode知识点总结 - 606
LeetCode 606. Construct String from Binary Tree 考点 难度 String Easy 题目 Given the root of a binary tree ...
- LeetCode知识点总结 - 977
LeetCode 977. Squares of a Sorted Array 考点 难度 Sorting Easy 题目 Given an integer array nums sorted in ...
- LeetCode知识点总结 - 377
LeetCode 377. Combination Sum IV 考点 难度 DP Medium 题目 Given an array of distinct integers nums and a t ...
最新文章
- pytorch model.train() 开启batchnormalize 和 dropout model.eval() 则会关闭dropout
- RedHat linux服务器对外开放指定端口
- 《第13章 猜拳游戏》
- Maven集成指令总结
- mysql建库权限_mysql数据库用户权限及建库脚本
- python查看list_reverseiterator object中的内容
- NumPy Cookbook 带注释源码 三、掌握 NumPy 常用函数
- RFM模型的理解和python案例分析
- Colmap中depth_map部分的源码
- WPF在资源内嵌入字体
- 智商情商哪个重要_你认为哪个更重要,情商还是智商?为什么?
- android打鸭子代码,打鸭子安卓版
- 【Windows Tips】关闭 Windows Defender
- ai怎么让图片任意变形_ai文字怎么随意变形?ai文字变形技巧教程
- 微信公众号开发教程(序)
- English Learning - Day20 作业打卡 2022.12.26 周一
- 经典的排错过程 expected unqualified-id before string constant
- ARM 微处理器的数据类型
- JUC第六讲:ThreadLocal/InheritableThreadLocal详解/TTL-MDC日志上下文实践
- Spring Boot集成阿里云视频点播服务的过程记录