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.em…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串切片 栈 日期 题目地址:https://leetcode.com/problems/backspace-string-compare/description/ 题目描述 Given two strings S and T, return if they are equal when both are typed into empty text…
[抄题]: 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"…
class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.size(); ,endt=; ;i<szs;i++) //get the result string of S { if(S[i]=='#') { ) ends--; } else S[ends++]=S[i]; } ;j<szt;j++) //get the result string of T {…
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". Exam…
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". Exam…
problem 942. DI String Match 参考 1. Leetcode_easy_942. DI String Match; 完…
problem 796. Rotate String solution1: class Solution { public: bool rotateString(string A, string B) { if(A.size()!=B.size()) return false; && B.size()==) return true;//errr... ; i<A.size(); ++i) { , i) == B) return true; } return false; } }; s…
problem 686. Repeated String Match solution1: 使用string类的find函数: class Solution { public: int repeatedStringMatch(string A, string B) { ; string t = A; while(t.size() < n2) { t += A; cnt++; } if(t.find(B) != string::npos) return cnt;//err. t += A; : -…
problem 606. Construct String from Binary Tree 参考 1. Leetcode_easy_606. Construct String from Binary Tree; 完…
problem 541. Reverse String II 题意: 给定一个字符串,每隔k个字符翻转这k个字符,剩余的小于k个则全部翻转,否则还是只翻转剩余的前k个字符. solution1: class Solution { public: string reverseStr(string s, int k) { int n = s.size(); int cnt = n / k; ; i<=cnt; i++) { ==) { if(i*k+k<n) reverse(s.begin()+i…
[CF1132F]Clear the String(动态规划) 题面 CF 题解 考虑区间\(dp\). 增量考虑,每次考虑最后一个字符和谁一起删去,然后直接转移就行了. #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define MAX 505 int f[MAX][MAX],n;char s[MAX]; int main() { scanf("%d%s…
[Hihocoder1413]Rikka with String(后缀自动机) 题面 Hihocoder 给定一个小写字母串,回答分别把每个位置上的字符替换为'#'后的本质不同的子串数. 题解 首先横跨'#'左右的串一定恰好只会出现一次,所以直接统计答案. 那么剩下的部分就是左右的本质不同的子串数. 我们把答案拆成三个部分,先是左侧本质不同子串的个数,再是右侧本质不同子串的个数.最后再减去既在左侧出现过,又在右侧出现过的串的个数. 左右两个直接用\(SAM\)算就好了. 在两侧同时出现过的,我们…
[CF886D]Restoration of string 题意:对于给定的一个母串,定义一个字符串是出现频率最多的,当且仅当它在母串中出现的次数最多(可以有多个出现次数最多的,出现的位置可以重叠). 现在给你一个字符串集合S,问你如果要求S中的所有字符串的出现频率都是最多的,最短的母串是什么.(如果有多个长度相同的母串,输出字典序最小的). |S|<=100000 题解:容易发现出现次数最多的一定是单个字符. 那么对于S中任意两个相邻的字符ab,一旦出现a后面就只能出现b.所以我们可以从a到b…
[HDU5421]Victor and String(回文树) 题面 Vjudge 大意: 你需要支持以下操作: 动态在前端插入一个字符 动态在后端插入一个字符 回答当前本质不同的回文串个数 回答当前回文串个数 题解 回文树前端插入的操作,学一学感觉并不难? 额外维护一下一个前端插入的\(last\) 然后就和后端插入一模一样,前端插入时就是前端插入的\(last\) 唯一会产生的影响的就是当前字符差完后, 发现现在的\(last\)就是整个串,那么就要更新另外一端的\(last\)为当前这一端…
[CF954I]Yet Another String Matching Problem(FFT) 题面 给定两个字符串\(S,T\) 求\(S\)所有长度为\(|T|\)的子串与\(T\)的距离 两个等长的串的距离定义为最少的,将某一个字符全部视作另外一个字符的次数. \(|T|<=|S|<=10^6\),字符集大小为\(6\) 题解 考虑如何快速计算两个串的答案,从左向右扫一遍,如果对应位置上有两个字符不同,检查在并查集中是否属于同一个集合,如果不属于则答案加一,同时合并两个集合.(这个就是…
[LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/magical-string/description/ 题目描述: A magical string S consists of only '1' and '2' and obeys the f…
[LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/decoded-string-at-index/description/ 题目描述: An encoded string S is given. To find and wri…
这是悦乐书的第327次更新,第350篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第197题(顺位题号是844).给定两个字符串S和T,如果两个字符串都输入到空文本编辑器中并且相等,则返回true. #表示退格符.例如: 输入:S ="ab#c",T ="ad#c" 输出:true 说明:S和T都变为"ac". 输入:S ="ab ##",T ="c#d#" 输出:true 说…
[Question] Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". [My Solution] Slice 切片 class Solution(object): def reverseString(self, s): """ :type s…
problem 1047. Remove All Adjacent Duplicates In String 参考 1. Leetcode_easy_1047. Remove All Adjacent Duplicates In String; 完…
problem 1170. Compare Strings by Frequency of the Smallest Character 参考 1. Leetcode_easy_1170. Compare Strings by Frequency of the Smallest Character; 完…
problem 806. Number of Lines To Write String solution: class Solution { public: vector<int> numberOfLines(vector<int>& widths, string S) { , len = ; for(auto ch:S) { int t = widths[ch-'a']; ) line++; len = (len+t>) ? t : len+t; } return…
problem 557. Reverse Words in a String III solution1:字符流处理类istringstream. class Solution { public: string reverseWords(string s) { string ans = "", t = ""; istringstream is(s);// while(is >> t) { reverse(t.begin(), t.end()); ans…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4030 访问. 给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果. # 代表退格字符. 输入:S = "ab#c", T = "ad#c" 输出:true 解释:S 和 T 都会变成 "ac". 输入:S = "ab##", T = "c…
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". Exam…
我们在C++的开发中经常会碰到string.char*以及CString,这三种都表示字符串类型,有很多相似又不同的地方,常常让人混淆.下面详细介绍这三者的区别.联系和转换: 各自的区别 char*: char*是一个指向字符的指针,是一个内置类型.可以指向一个字符,也可以表示字符数组的首地址(首字符的地址).我们更多的时候是用的它的第二的功能,来表示一个字符串,功能与字符串数组char ch[n]一样,表示字符串时,最后有一个 '\0'结束符作为字符串的结束标志. [例1] #include…
1.网络上获取的String Json格式转化为对象获取数据: 需要的包:Gson Maven依赖: <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>…
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". Exam…
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". Exam…