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. DW-ODS

    ODS (操作数据存储) 编辑 讨论 操作数据存储ODS(Operational Data Store)是数据仓库体系结构中的一个可选部分,也被称为贴源层.ODS具备数据仓库的部分特征和OLTP系统的 ...

  2. learning java Cloneable

    class Address{ String Detail; public Address(String detail){ this.Detail = detail; } } class User im ...

  3. sshfs 试用

    sshfs 是基于fuse 开发的可以像使用本地系统一样,通过ssh 协议访问远端服务器文件,有好多方便的用途 数据同步 数据加密访问 做为共享数据卷(基于给容器使用) 安装 yum install ...

  4. Codevs 3002 石子归并 3(DP四边形不等式优化)

    3002 石子归并 3 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w[i], 每次 ...

  5. TCP四路挥手问题:

    1.不管被动和主动,只要发送Fin分节就关闭此端应用层.那么挥手时S接到Fin,此刻C已经关闭应用层,那么S再发送消息岂不是无用,浪费网络资源?

  6. mybatis-sqlite日期类型对应关系

    1.问题 sqlite数据库 user表,create_time字段,类型DATETIME,设置默认值datetime('now') mybatis,User实体,createTime类型为java. ...

  7. centos安装jdk1.8的三种方法

    一.手动解压安装包: 1.在user目录下新建java文件夹:   # cd /usr/   # mkdir java   # cd java 2.下载jdk1.8,进入http://www.orac ...

  8. Vscode 保存文件就会自动添加注释

    Vscode 保存文件就会自动添加注释   原因是:安装了插件造成的..   文章来源:刘俊涛的博客 欢迎关注公众号.留言.评论,一起学习. _____________________________ ...

  9. Intellij IDEA的Facets和Artifacts

    Facets: Facets表述了在Module中使用的各种各样的框架.技术和语言.这些Facets让Intellij IDEA知道怎么对待module内容,并保证与相应的框架和语言保持一致. 使用F ...

  10. Android日期操作

    第一种方法 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// ...