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. SQL Server Default Trace查看是谁对数据库进行了DDL操作

    在我们的工作中可能会遇到这样一种情形.由于数据库中某些对象被altered/created/deleted,造成我们的应用程序crash. 当我们把问题解决之后,老板可能会问发生了什么?为什么会这样? ...

  2. php自定义函数之匿名函数

    所谓匿名,就是没有名字. 匿名函数,也就是没有函数名的函数.直线电机参数 匿名函数的第一种用法,直接把赋数赋值给变量,调用变量即为调用函数. 匿名函数的写法比较灵活. 1.变量函数式的匿名函数 < ...

  3. vue中插槽作用域的使用

    一.插槽作用域 1.简单来说就是带参数的插槽: 2.使用方式: 在组件标签内部加一个template标签 在template标签上加一个属性scope 值随意书写 在组件内部用slot进行接受,如果给 ...

  4. 常见的 eslint 基本报错信息

    Missing semicolon 缺少分号 Missing space before opening brace 左大括号前缺少空格 Trailing spaces not allowed 不允许尾 ...

  5. 洛谷P5017摆渡车

    题目 一道做法多种多样的题,DP做法的状态也很多. 我用\(dp[i]\)表示在第i秒发车的时间和,然后dp方程就很好写了 \(dp[i] = dp[j] + i车的等待时间\)j属于i-2m ~ i ...

  6. vue项目开发中遇到的几个问题

    1.使用elment或者mintUI库时,需要全局引入ui库的css文件:然后在修改自己样式时,需要将自己的css文件引入到main.js中才会生效,全局引用2.使用v-html展示dom字符串时,相 ...

  7. 对okhttp参数的一些思考

    背景 项目中使用OkHttp访问三方服务 参数 创建okhttp客户端类的时候需要设置一些参数,有些可能是坑,仅供参考: client = new OkHttpClient.Builder() .di ...

  8. 像母语者一样说美语 How to Improve Spoken American English - Sound like a Native Speaker

    视频讲解: 视频详情见:https://www.bilibili.com/video/av75075387/ 总结分析: 001 要点总结: 1. 本富兰克林方法: 要你写下一切听到的东西 2. 辅音 ...

  9. 2019全国大学生信息安全竞赛ciscn-writeup(4web)

    web1-JustSoso php伪协议获取源码 ?file=php://filter/read=convert.base64-encode/resource=index.php index.php ...

  10. Java利用FastJson一行代码转List<Map>为List<Bean>

    /** * 字符串 -> json对象.实体对象.Map.List.List<Map> */ // 字符串 -> json对象 JSONObject json = JSON.p ...