leetcode844
class Solution {
public:
bool backspaceCompare(string S, string T) {
stack<char> ST1;
for (int i = ; i < S.length(); i++)
{
char c = S[i];
if (c == '#')
{
if (!ST1.empty())
{
ST1.pop();
}
}
else
{
ST1.push(c);
}
}
stack<char> ST2;
for (int i = ; i < T.length(); i++)
{
char c = T[i];
if (c == '#')
{
if (!ST2.empty())
{
ST2.pop();
}
}
else
{
ST2.push(c);
}
}
if (ST1.size() != ST2.size())
{
return false;
}
else
{
for (int i = ; i < ST1.size(); i++)
{
char s = ST1.top();
ST1.pop();
char t = ST2.top();
ST2.pop();
if (s != t)
{
return false;
}
}
}
return true;
}
};
leetcode844的更多相关文章
- [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-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 = " ...
- leetcode844 Backspace String Compare
""" Given two strings S and T, return if they are equal when both are typed into empt ...
- LeetCode844 比较含退格的字符串
题目描述: 给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果. # 代表退格字符. 示例 1: 输入:S = "ab#c", T = ...
- LeetCode-Stack-Easy
简单题 1. 有效的括号(leetcode-20) 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 1. 左括号必须用相同类型的右括 ...
随机推荐
- [Java]如何为一个自定义类型的List排序。
好吧,三年了,又重拾我的博客了,是因为啥呢,哈哈哈.今天被问到一个题目,当场答不出来,动手动的少了,再此记录下来. Q:有一个MyObject类型的List,MyObject定义如下: class M ...
- (function($){...})(jQuery)与$(function(){...})区别
$(function(){...}) 这种写法和jQuery(function(){...}),$(document).ready(function(){...})作用一样,表示文档载入后需要运行的代 ...
- JSP学习(四)JSP属性范围
P属性范围 四种属性范围分别指以下四种: 当前页page:一个属性只能在一个页面中取得,跳转到其他页面无法取得 一次服务器请求request:一个页面中设置的属性,只要经过了服务器跳转,则跳转之后的页 ...
- python ctypes 和windows DLL互相调用
图片项目
- $x \rightarrow \infty$时多项式型函数的极限
\[ \lim_{x \rightarrow \infty} \frac{\sqrt{4x^6-5x^5}-2x^3}{\sqrt[3]{27x^6+8x}} \\ =\lim_{x \rightar ...
- k8s helm 包管理私服chartmuseum 安装
备注: 预备环境需要安装helm 1. 安装chartmuseum 参考 # on Linux curl -LO https://s3.amazonaws.com/chartmuseum/re ...
- fatal: The remote end hung up unexpectedly解决办法
$ git config --global http.postBuffer 2428000 git config http.postBuffer 524288000 配置完成后 git pull一下, ...
- Java中文件的常用操作
一.文件的移动 File afile =new File("D:\\workspace\\Test\\test.avl"); if(afile.renameTo(new File ...
- 收藏一下mybatis全局参数配置
http://blog.csdn.net/shaoduo/article/details/54285981
- bzoj1089严格n元树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1089 这是一种套路:记录“深度为 i ”的话,转移需要讨论许多情况:所以可以记录成“深度&l ...