【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 ...
随机推荐
- [matlab工具箱] 曲线拟合Curve Fitting
——转载网络 我的matlab版本是 2016a 首先,工具箱如何打开呢? 在 apps 这个菜单项中,可以找到很多很多的应用,点击就可以打开具体的工具窗口 本文介绍的工具有以下这些: curve F ...
- GSS1 A - Can you answer these queries I
//题意:询问一段区间的最大子序列的值. //做法:维护四个值:包含当前区间左端点的最大子区间LM,包含当前区间右端点的最大子区间RM.当前区间的最大子区间M, 当前区间的区间和S //tree[ro ...
- 《挑战30天C++入门极限》C++的iostream标准库介绍(3)
C++的iostream标准库介绍(3) C语言提供了格式化输入输出的方法,C++也同样,但是C++的控制符使用起来更为简单方便,在c++下有两中方法控制格式化输入输出. 1.有流对象的成员函 ...
- 未公开函数 NtQuerySystemInfoMation 遍历进程信息,获得进程的用户名(如: system,Admin..)
目录 遍历进程用户名 代码例子 遍历进程用户名 代码例子 #include <windows.h> #include <iostream> #include <COMDE ...
- 超级详细的git使用指北
原文地址:https://www.cnblogs.com/wupeixuan/p/11947343.html 1.0 安装和配置 1.1 Git 安装 1.2 Git 配置 2.0 Git 基 ...
- 和小哥哥一起刷洛谷(6) 图论之SPFA算法
关于\(spfa\) spfa伪代码: void spfa(s){ 最短路数组全部设为无限大; 队列 q; 起点s入队; s离s的距离设为零; while(队列非空){ 取出队首;弹出队首; for( ...
- JavaScript data types and data structures
JavaScript data types and data structures Programming languages all have built-in data structures, b ...
- Java 从入门到进阶之路(十六)
在之前的文章我们介绍了一下 Java 中类的多态,本章我们来看一下 Java 中类的内部类. 在 Java 中,内部类分为成员内部类和匿名内部类. 我们先来看一下成员内部类: 1.类中套类,外面的叫外 ...
- 【转】Android检查手机是否被root
目前来说Android平台并没有提供能够root检查的工具.但是我们可以通过两种方式来判断 手机里面是否有su文件 这个su文件是不是能够执行 但是这两种检查方式都存在缺点. 第一种存在误测和漏测的情 ...
- 《Linux性能及调优指南》 Linux进程管理
版权所有: 原文名称:<Linux Performance and Tuning Guidelines> 原文地址:http://www.redbooks.ibm.com/abstract ...