【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 ...
随机推荐
- Vue的响应式系统
Vue的响应式系统 我们第一次使用Vue的时候,会感觉有些神奇,举个例子: <div id="app"> <div>价格:¥{{price}}</di ...
- admin站点管理
admin中的显示 class Saltstack_GroupAdmin(admin.ModelAdmin): list_display = ['group_name','salt_minion_id ...
- easyui181版本使用记录
easyui181版本下载地址 简单java+easyui181版本demo下载 注意前端页面的ajax请求路径对应后端 如果再加强样式可使用adminLTE
- 连接到 redis 服务
连接到 redis 服务 <?php //连接本地的 Redis 服务 $redis = new Redis(); $redis->connect('127.0.0.1', 6379); ...
- flutter 从接口获取json数据显示到页面
如题,在前端,是个很简单的ajax请求,json的显示,取值都很方便,换用dart之后,除了层层嵌套写的有点略难受之外,还有对json的使用比js要麻烦 1. 可以参照 flutter-go 先封装一 ...
- 洛谷 P1004 方格取数 题解
P1004 方格取数 题目描述 设有 \(N \times N\) 的方格图 \((N \le 9)\),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字\(0\).如下图所示(见样例): ...
- webpack-merge使用说明
webpack-merge 配置分离 随着我们业务逻辑的增多,图片.字体.css.ES6以及CSS预处理器和后处理器逐渐的加入到我们的项目中来,进而导致配置文件的增多,使得配置文件书写起来比较繁琐 ...
- 怎么把分化成元,并且保留两位小数,用vue来做
<el-table-column prop="amount" label="申请提现金额" width="120" align=&qu ...
- 实验五 遇到的问题:openssl: error while loading shared libraries: libssl.so.1.1
遇到的问题 命令行:linux@ubuntu64-vm:~/exp/exp5$ openssl enc -aes-128-cbc -in test_aes.txt -out out.txt -pass ...
- Ubuntu+QEMU+Xv6环境搭建
操作系统:Ubuntu 16.04 32位 虚拟机:VMware 模拟器:QEMU 之前有一台centos 64位虚拟机,使用源码安装配置环境,出了一些列问题,最终环境都已经配好了,也能够在qemu上 ...