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的更多相关文章

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

  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. Leetcode844.Backspace String Compare比较含退格的字符串

    给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果. # 代表退格字符. 示例 1: 输入:S = "ab#c", T = " ...

  4. leetcode844 Backspace String Compare

    """ Given two strings S and T, return if they are equal when both are typed into empt ...

  5. LeetCode844 比较含退格的字符串

    题目描述: 给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果. # 代表退格字符. 示例 1: 输入:S = "ab#c", T = ...

  6. LeetCode-Stack-Easy

    简单题 1. 有效的括号(leetcode-20) 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 1. 左括号必须用相同类型的右括 ...

随机推荐

  1. 6LowPan 开发之开山篇

    本文参考: http://blog.csdn.net/xukai871105/article/details/9204101   1.基本概念   1) instant contikit    Ubu ...

  2. 每天一个linux命令:【转载】touch命令

    linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a    ...

  3. WebStorm的下载与安装

    百度搜索: 链接:http://www.jetbrains.com/webstorm/ 链接:http://www.jetbrains.com/student/ 学生免费授权计划 请从正规来源下载软件 ...

  4. 《DSP using MATLAB》示例Example 8.27

    %% ------------------------------------------------------------------------ %% Output Info about thi ...

  5. 使用反相器的rc振荡电路

    多谐振荡器是一种自激振荡电路,该电路在接通电源后无需外接触发信号就能产生一定频率和幅值的矩形脉冲波或方波.由于多谐振荡器在工作过程中不存在稳定状态,故又称为无稳态电路. 一.门电路组成的多谐振荡器 1 ...

  6. uva 11237 - Halloween treats(抽屉原理)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/37612503 题目链接:uva 11237 ...

  7. TCP和UDP通信(C#网络编程) ---- 系列文章

    文章系列目录 C#网络编程系列文章(一)之Socket实现异步TCP服务器 C#网络编程系列文章(二)之Socket实现同步TCP服务器 C#网络编程系列文章(三)之TcpListener实现异步TC ...

  8. 如何使用 nslookup 查域名的 ttl

    如何使用 nslookup 查域名的 ttl nslookup 经常用,但是最近才使用到查 ttl 的信息. 域名的 ttl 也是网站优化的一个重要参数. nslookup -d www.fastad ...

  9. @RequestParam和@RequestBody的区别-------springMVC

    https://blog.csdn.net/qq_27093465/article/details/50519444 @RequestParam 1,用来处理Content-Type: 为 appli ...

  10. jieba分词初学

    昨天,做的那个数据分析报告用到了jieba分词.但是只是借用了别人的部分代码.具体函数代表什么还不太明白.今天去官网研究了下..... jieba官网简介 "结巴"中文分词:做最好 ...