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. 【剑指offer】栈的压入弹出序列,C++实现(举例)

    原创文章,转载请注明出处! 本题牛客网地址 博客文章索引地址 博客文章中代码的github地址 1.题目 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为第一个序列的出栈序列.注意 ...

  2. notes on Art Pipeline

    Do not add complex clothes/facial hair to a model for Mixamo to auto rig, it will cause confusion. A ...

  3. RankNet

    RankNet 论文的笔记:Learning to rank using gradient descent. 模型 特征 \(\mathbf x_i \in \mathbb R^d\) 模型函数:\( ...

  4. Android:BroadcastReceiver

    参考:<第一行代码:Android> 郭霖(著)   Broadcast分类 注册方式: 动态广播 在代码中注册receiver 一定要手动在onDestroy()时调用unregiste ...

  5. BJOI 模拟赛 #3 题解

    T1 一个网格,每个点有权值,求有多少条路径权值乘积不小于 $n$ $R,C \leq 300, n \leq 10^6$ sol: 暴力 dp 是 $O(R \times C \times n)$ ...

  6. C的文件操作函数

    fgetc(FILE *)意为从文件指针stream指向的文件中读取一个字符,读取一个字节后,光标位置后移一个字节fputc(char,FILE*)将字符ch写到文件指针fp所指向的文件的当前写指针的 ...

  7. python笔记-8(logging模块、re模块、栈与队列)

    一.Logging模块日志 1.logging导入 Import logging 2.知道5个日志级别的等级关系 Debug->info->warning->error->cr ...

  8. direct2d封装

    图片项目

  9. numpy 的三角函数运算

    numpy 的三角函数运算 cos, cosh, sin sinh, tan, tanh regular 和 hyperbolic 三角函数 arccos, arccosh, arcsin, arcs ...

  10. smarty缓存的使用

    <?php require './smarty/Smarty.class.php'; $sm = new Smarty; //$sm->force_compile = true; $sm- ...