【Leetcode_easy】796. Rotate String】的更多相关文章

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…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/rotate-string/description/ 题目描述 We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost charac…
problem 942. DI String Match 参考 1. Leetcode_easy_942. DI String Match; 完…
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…
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…
344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) { if(s.empty()) return; ; ; while(start < end){ char tmp = s[end]; s[end] = s[start]; s[start] = tmp; start++; end--; } return; } }; 541. Reverse Strin…
[Hihocoder1413]Rikka with String(后缀自动机) 题面 Hihocoder 给定一个小写字母串,回答分别把每个位置上的字符替换为'#'后的本质不同的子串数. 题解 首先横跨'#'左右的串一定恰好只会出现一次,所以直接统计答案. 那么剩下的部分就是左右的本质不同的子串数. 我们把答案拆成三个部分,先是左侧本质不同子串的个数,再是右侧本质不同子串的个数.最后再减去既在左侧出现过,又在右侧出现过的串的个数. 左右两个直接用\(SAM\)算就好了. 在两侧同时出现过的,我们…