【Leetcode_easy】844. Backspace String Compare
problem
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的更多相关文章
- 【LeetCode】844. Backspace String Compare 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串切片 栈 日期 题目地址:https://le ...
- 844. Backspace String Compare判断删除后的结果是否相等
[抄题]: Given two strings S and T, return if they are equal when both are typed into empty text editor ...
- 844. Backspace String Compare
class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...
- [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 ...
- [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 ...
- 【Leetcode_easy】942. DI String Match
problem 942. DI String Match 参考 1. Leetcode_easy_942. DI String Match; 完
- 【Leetcode_easy】796. Rotate String
problem 796. Rotate String solution1: class Solution { public: bool rotateString(string A, string B) ...
- 【Leetcode_easy】686. Repeated String Match
problem 686. Repeated String Match solution1: 使用string类的find函数: class Solution { public: int repeate ...
- 【Leetcode_easy】606. Construct String from Binary Tree
problem 606. Construct String from Binary Tree 参考 1. Leetcode_easy_606. Construct String from Binary ...
随机推荐
- C++命令空间使用和编译
先创建目录结构 src bin obj lib include 1.创建命名空间 创建一个头文件include/head.h; #ifndef _GOOD_H #define _GOOD_H name ...
- Problem 7 树状数组+转化
$des$有一棵 $n$ 个点的以 $1$ 为根的树, 以及 $n$ 个整数变量 $x_i$ .树上 $i$ 的父亲是 $f_i$ ,每条边 $(i,f_i)$ 有一 个权值 $w_i$ ,表示一个方 ...
- Bzoj 2440: [中山市选2011]完全平方数(莫比乌斯函数+容斥原理+二分答案)
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MB Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平 ...
- LOJ2434. 「ZJOI2018」历史 [LCT]
LOJ 思路 第一眼看似乎没有什么思路,试着套个DP上去:设\(dp_x\)表示只考虑\(x\)子树,能得到的最大答案. 合并的时候发现只有\(x\)这个点有可能做出新的贡献,而做出新贡献的时候必然是 ...
- GoCN每日新闻(2019-09-29)
1. 干货满满的Go Modules和goproxy.cn https://juejin.im/post/5d8ee2db6fb9a04e0b0d9c8b 2. gnet: 一个轻量级且高性能的 Go ...
- org.apache.ibatis.cache.CacheException: Error serializing object
异常: 十二月 26, 2017 3:38:05 下午 org.apache.jasper.servlet.TldScanner scanJars 信息: At least one JAR was s ...
- Multi-Temporal SAR Data Large-Scale Crop Mapping Based on U-Net Model(利用U-net对多时相SAR影像获得作物图)
对哨兵1号的多时相双极化SAR数据进行预处理,得到18个日期的VV和VH共36景影像,通过ANOVA和JM距离分析,选其中ANOVA得到的F值最高的6景影像.真值用LC8数据和地面调查,目视解译得到标 ...
- 【随记】安装SQL Server 2008 R2 提示创建usersettings/microsoft.sqlserver.configuration.landingpage.properties.se
在安装SQL Server 2008 R2 提示创建usersettings/microsoft.sqlserver.configuration.landingpage.properties.se.. ...
- Bootstrap select 多选并获取选中的值
代码: <!DOCTYPE html><html> <head> <meta charset="UTF-8"> < ...
- UML图中时序图的基本用法
快速阅读 序列图主要用来更直观的表现各个对象交互的时间顺序,将体现的重点放在 以时间为参照,各个对象发送.接收消息,处理消息,返回消息的 时间流程顺序,也称为时序图. 里面用到的基本元素如下: 角色- ...