Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >844. Backspace String Compare

844. Backspace String Compare

作者头像
用户1631856
发布于 2018-09-27 09:00:45
发布于 2018-09-27 09:00:45
81300
代码可运行
举报
文章被收录于专栏:老秦求学老秦求学
运行总次数:0
代码可运行

Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.

Example 1:

Input: S = "ab#c", T = "ad#c" Output: true Explanation: Both S and T become "ac".

Example 2:

Input: S = "ab##", T = "c#d#" Output: true Explanation: Both S and T become "".

Example 3:

Input: S = "a##c", T = "#a#c" Output: true Explanation: Both S and T become "c".

Example 4:

Input: S = "a#c", T = "b" Output: false Explanation: S becomes "c" while T becomes "b". Note:

1 <= S.length <= 200 1 <= T.length <= 200 S and T only contain lowercase letters and '#' characters.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class Solution {
public:
    bool backspaceCompare(string S, string T) {
        string s = "", t="";
        for(int i=0;i<S.length();i++){
            if(S[i] == '#'){//注意是字符之间的比较,不能用字符和字符串进行比较-->错误ISO C forbids comparison between pointer and integer [-fpermissive]
                if(s.length()!=0)
                    s.pop_back();
            }
            else{
                s+=S[i];
            }
        }
        for(int i=0;i<T.length();i++){
            if(T[i] == '#'){
                if(t.length()!=0)
                    t.pop_back();
            }
            else{
                t+=T[i];
            }
        }
        return s==t;
    }
};
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-09-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
leetcode-844-比较含退格的字符串(用vector取代stack)
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。 # 代表退格字符。
chenjx85
2018/08/01
5300
45 Increasing Decreasing String
Given a string s. You should re-order the string using the following algorithm:
devi
2021/08/18
3510
LeetCode 844. 比较含退格的字符串
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。 # 代表退格字符。
Michael阿明
2020/07/13
5210
【leetcode刷题】T24-比较含退格的字符串
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.
木又AI帮
2019/07/17
4610
【一天一大 lee】比较含退格的字符串 (难度:简单) - Day20201019
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。# 代表退格字符。
前端小书童
2020/11/03
3080
【一天一大 lee】比较含退格的字符串 (难度:简单) - Day20201019
leetcode栈之比较含退格的字符串
这里借助栈,遍历string的char,遇到#时在栈不为空的时候pop一下,非#时则push数据到栈中;之后对比两个栈的元素来判断是否相等。
code4it
2020/10/05
4580
leetcode栈之比较含退格的字符串
【算法千题案例】每日一练LeetCode打卡——102.比较含退格的字符串
给定 s 和 t 两个字符串,当它们分别被输入到空白的文本编辑器后,请你判断二者是否相等。# 代表退格字符。
呆呆敲代码的小Y
2022/01/24
3320
【算法千题案例】每日一练LeetCode打卡——102.比较含退格的字符串
比较含退格的字符串!
力扣题目链接:https://leetcode-cn.com/problems/backspace-string-compare
代码随想录
2021/12/24
3.1K0
比较含退格的字符串!
LeetCode | 844. 比较含退格的字符串
这道题目是要进行向前的消除,当满足条件时,除了消除当前的字符,也会消除当前字符之前的字符,此时可以使用栈结构来进行操作。时间复杂度和空间复杂度,都为O(N)。
码农UP2U
2021/04/26
7090
LeetCode | 844. 比较含退格的字符串
LeetCode 844 比较含退格的字符串
力扣 844 比较含退格的字符串 | LeetCode 844 Backspace String Compare | 算尽天下系列第 11 期 | 栈/双指针
凝神长老
2020/04/16
6450
【算法题解】 Day15 栈
给定 s 和 t 两个字符串,当它们分别被输入到空白的文本编辑器后,如果两者相等,返回 true 。# 代表退格字符。
sidiot
2023/08/26
1860
【算法题解】 Day15 栈
脚撕LeetCode(844)Easy
题目地址:https://leetcode-cn.com/problems/range-sum-query-mutable/
JathonKatu
2021/03/16
2540
【Leetcode -844.比较含退格的字符串 -1047.删除字符串中的所有相邻重复项】
题目:给定 s 和 t 两个字符串,当它们分别被输入到空白的文本编辑器后,如果两者相等,返回 true 。# 代表退格字符。 注意:如果对空文本输入退格字符,文本继续为空。
YoungMLet
2024/03/01
2090
LeetCode-算法-双指针-第18天
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。 # 代表退格字符。注意:如果对空文本输入退格字符,文本继续为空。
布衣者
2021/09/07
2390
ISO C forbids comparison between pointer and integer [-fpermissive]
异常:ISO C forbids comparison between pointer and integer [-fpermissive] 意思是:指针和整数比较出错;禁止指针和整数进行比较。 S[i]是字符,”#”表示一个字符串的首地址。
公众号-不为谁写的歌
2020/07/23
1.6K0
leetcode-830-Positions of Large Groups
题目描述: In a string S of lowercase letters, these letters form consecutive groups of the same character. For example, a string like S = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z" and "yy". Call a group large if it has 3 or more characters.  We would
chenjx85
2018/05/21
6850
54 Minimum Number of Steps to Make Two Strings Anagram
Given two equal-size strings s and t. In one step you can choose any character of t and replace it with another character.
devi
2021/08/18
2940
Leetcode: Reverse Words in a String
题目: Given an input string, reverse the string word by word.
卡尔曼和玻尔兹曼谁曼
2019/01/22
3960
leetcode389.Find The Difference
假设两个只包含小写字母的字符串s和t,其中t是s中字母的乱序,并在某个位置上添加了一个新的字母。问添加的这个新的字母是什么?
眯眯眼的猫头鹰
2019/03/13
3170
String - 44. Wildcard Matching
Wildcard Matching Given an input string (s) and a pattern (p), implement wildcard pattern matching w
ppxai
2020/09/23
4870
相关推荐
leetcode-844-比较含退格的字符串(用vector取代stack)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验