【Leetcode_easy】796. Rotate String
problem
solution1:
class Solution {
public:
bool rotateString(string A, string B) {
if(A.size()!=B.size()) return false;
if(A.size()== && B.size()==) return true;//errr...
for(int i=; i<A.size(); ++i)
{
if(A.substr(i, A.size()-i)+A.substr(, i) == B) return true;
}
return false;
}
};
solution2:
class Solution {
public:
bool rotateString(string A, string B) {
return (A.size()==B.size() && ((A+A).find(B)!=string::npos));
}
};
参考
1. Leetcode_easy_796. Rotate String;
2. Grandyang;
完
【Leetcode_easy】796. Rotate String的更多相关文章
- 【LeetCode】796. Rotate String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【Leetcode_easy】942. DI String Match
problem 942. DI String Match 参考 1. Leetcode_easy_942. DI String Match; 完
- 【Leetcode_easy】844. Backspace String Compare
problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...
- 【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 ...
- 【leetcode_easy】541. Reverse String II
problem 541. Reverse String II 题意: 给定一个字符串,每隔k个字符翻转这k个字符,剩余的小于k个则全部翻转,否则还是只翻转剩余的前k个字符. solution1: cl ...
- 【CF1132F】Clear the String(动态规划)
[CF1132F]Clear the String(动态规划) 题面 CF 题解 考虑区间\(dp\). 增量考虑,每次考虑最后一个字符和谁一起删去,然后直接转移就行了. #include<io ...
- leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String
344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...
- 【Hihocoder1413】Rikka with String(后缀自动机)
[Hihocoder1413]Rikka with String(后缀自动机) 题面 Hihocoder 给定一个小写字母串,回答分别把每个位置上的字符替换为'#'后的本质不同的子串数. 题解 首先横 ...
随机推荐
- 利用selenium自动化测试样例一
import argparse import logging import psycopg2 import datetime,time import os,sys from selenium impo ...
- django设置时区与语言
django的目录下,django/conf/locale,这个目录下,看有什么语言包, zh_Hans代表中文简体,zh_Hant代表中文繁体,设置即可. TIME_ZONE设置为:Asia/Sha ...
- 实现strStr()函数
方法一:暴力解法 int strStr(string haystack, string needle) { if (needle.empty()) ; int M = haystack.size(); ...
- Hdu 4312-Meeting point-2——哈夫曼距离与切比雪夫距离
题意 从 $n$ 个点中选择一点,使得其他点到其的切比雪夫距离最小($0 < n \leq 1e5$). 分析 定理:$(x_1, y_1)$ 与 $(x_2, y_2)$ 的曼哈顿距离等于 $ ...
- 2019牛客多校A All-one Matrices——单调栈
题目 求非嵌套子矩阵的个数. 分析 单调栈的套路题(类似的有求最大子矩阵). 首先,按列预处理,每个位置化成连续1的个数. 例如,左边的图转成右边. 然后枚举 ...
- Python爬虫:BeautifulSoup用法总结
原文 BeautifulSoup是一个解析HTML或XML文件的第三方库.HTML或XML文件可以用DOM模型解释.一般包含三种节点: 元素节点 - 通常指HTML 或 XML的标签 文本节点 - 标 ...
- HTML怎么块外横向剧中
HTML 块外横向剧中 在HTML中有一个块外横向剧中的代码 那就是margin:0 auto 这个能是块内元素横向剧中 剧中前: 剧中后
- HashMap的底层结构和原理
http://youzhixueyuan.com/the-underlying-structure-and-principle-of-hashmap.html HashMap是Java程序员使用频率最 ...
- 块状链表 bzoj 3343教主的魔法
//块状链表//分块排序,然后每次查找时在暴力查找头和尾两个块.//中间那些块,因为有序所以只需2分查找即可.我用的是lower_pound();//插入是,也是头和尾暴力插入,中间那些加到一个累计里 ...
- 爬虫与seo优化
爬虫及爬行方式 爬虫有很多名字,比如web机器人.spider等,它是一种可以在无需人类干预的情况下自动进行一系列web事务处理的软件程序.web爬虫是一种机器人,它们会递归地对各种信息性的web站点 ...