problem

844. Backspace String Compare

solution1:

class Solution {
public:
bool backspaceCompare(string S, string T) {
return backspace(S)==backspace(T);
}
string backspace(string str)
{
string res ="";
for(auto ch:str)
{
if(ch=='#')
{
if(!res.empty()) res.pop_back();
}
else res.push_back(ch);
}
return res;
}
};

solution2:

class Solution {
public:
bool backspaceCompare(string S, string T) {
string s = "", t = "";
for(auto ch:S) ch=='#' ? (s.empty()? void():s.pop_back()) : s.push_back(ch);//err...
for(auto ch:T) ch=='#' ? (t.empty()? void():t.pop_back()) : t.push_back(ch);
return s==t;
}
};

参考
1. Leetcode_easy_844. Backspace String Compare;

2. grandyang;

【Leetcode_easy】844. Backspace String Compare的更多相关文章

  1. 【LeetCode】844. Backspace String Compare 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串切片 栈 日期 题目地址:https://le ...

  2. 844. Backspace String Compare判断删除后的结果是否相等

    [抄题]: Given two strings S and T, return if they are equal when both are typed into empty text editor ...

  3. 844. Backspace String Compare

    class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...

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

  5. [LeetCode&Python] Problem 844. Backspace String Compare

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  6. 【Leetcode_easy】942. DI String Match

    problem 942. DI String Match 参考 1. Leetcode_easy_942. DI String Match; 完

  7. 【Leetcode_easy】796. Rotate String

    problem 796. Rotate String solution1: class Solution { public: bool rotateString(string A, string B) ...

  8. 【Leetcode_easy】686. Repeated String Match

    problem 686. Repeated String Match solution1: 使用string类的find函数: class Solution { public: int repeate ...

  9. 【Leetcode_easy】606. Construct String from Binary Tree

    problem 606. Construct String from Binary Tree 参考 1. Leetcode_easy_606. Construct String from Binary ...

随机推荐

  1. [Schematics] 1. Copy and Manipulate Template

    1. Create a src/my-component/files/src/app directory to hold your templates. mkdir -p src/my-compone ...

  2. LOJ P10176 最大连续和 题解

    每日一题 day29 打卡 Analysis 朴素的DP方程为: dp[i]=max{sum[i]-sum[j-1]}; 对于每个i 需要用单调队列维护最小的sum[j-1] 注意: 1.tail初值 ...

  3. MongoDB 查看集合的统计信息

    和 RDBMS 一样, MongoDB 同样存储集合的统计信息,通过调用命令 db.collection.stats() 可以方便的查看集合的统计信息. --1 查看集合 things 的统计信息 r ...

  4. (尚001)Vue框架介绍

    框架出现时间: Angular -->React(组件化+虚拟动) -->Vue(读作view) 1.Vue.js是什么?(作者:尤雨溪(一位华裔前Google工程师))        尤 ...

  5. codevs:1462 素数和:给定2个整数a,b 求出它们之间(不含a,b)所有质数的和。

    #include<iostream>#include<cstdio>#include<cmath>using namespace std;int main(){ i ...

  6. 洛谷P1325 雷达安装

    题目 考虑对于一个小岛,如果有雷达可以覆盖它,则这些雷达肯定在一个区间里,则原题内容则变为区间选点问题 #include <bits/stdc++.h> using namespace s ...

  7. [nodejs]修改全局包位置,修复npm安装全局模块命令失效。好记性不如烂笔头

    修复npm -g 全局安装命令失效,好的吧不得不承认,好记性不如烂笔头,我居然会忘记方法哈哈哈 Linux安装nodejs sudo apt install node sudo apt install ...

  8. Three.js实现滚轮放大展现不同的模型

    目录 Three.js实现滚轮放大展现不同的模型 修改OrbitControls.js的源码 OrbitControls在透视相机(PerspectiveCamera)的控制原理 具体实现 Three ...

  9. <c:choose>

    备注一下属性 DIV没有VALUE属性     <c:choose> <c:when test="${yggModel.type=='0'}">食品< ...

  10. rsync 使用ssh协议免密

    rsync远程传输避免密码输入 每次rsync远程传输时都需要输入用户在远程机器上的密码,这样导致无法在后台自动运行rsync,可采用秘钥文件来替代人工输入密码的方式来解决. 第一步 在本地机器上使用 ...