【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 给定一个小写字母串,回答分别把每个位置上的字符替换为'#'后的本质不同的子串数. 题解 首先横 ...
随机推荐
- 在使用rem布局的时候,遇到的样式排版混乱问题,
在使用rem布局的时候,遇到的样式排版混乱问题, 问题1:设置字体为rem单位,但是没有设置line-height为100%, 即 * { line-height: 1; ...
- 【Mac】打开配置文件,添加/修改环境变量
打开文件编辑器: 进入终端,输入open -e .bash_profile或者open -t ~/.bash_profile 打开profile文件 填写配置的环境变量: #示例代码 export ...
- CSS定位有几种?分别描述其不同
static(静态定位):即默认值,元素框正常生成的,top.right.bottom.left这些偏移属性不会影响静态定位的正常显示(属性不应用): relative(相对定位):元素相对自身偏移某 ...
- 【Winfrom-无边框窗体】Winform如何拖动无边框窗体?
去掉边框 this.FormBorderStyle = FormBorderStyle.None; 方法一: Point mouseOff;//鼠标移动位置变量 bool leftFlag;//标签是 ...
- HTML 003 元素
HTML 元素 HTML 文档由 HTML 元素定义. HTML 元素 开始标签 * 元素内容 结束标签 * <p> 这是一个段落 </p> <a href=" ...
- Linux 内存分配失败(关于overcommit_memory)
1.问题现象和分析:测试时发现当系统中空闲内存还有很多时,就报内存分配失败了,所有进程都报内存分配失败:sshd@localhost:/var/log>free tota ...
- Postgresql 物理备份冷备份 与 热备份
一.冷备份 将数据库停下来,然后把数据库的PGDATA目录拷贝下来就可以了. PostgreSQL把与数据库实例有关的配置文件和数据文件都放在PGDATA目录下,所以做冷备份很简单. 二.热备份 热备 ...
- Python中字符串与字节之间相互转换
Python中字符串与字节之间相互转换 a = b"Hello, world!" # bytes object b = "Hello, world!" # ...
- 对拍——>bat
为了凸显对拍滴重要性.就拿来当置顶啦! ——本来是那样想的 ---------------------------------------------------------------------- ...
- Ubuntu16.04 apache2+php7.0+mysql5.7环境搭建
今天配置一下web环境,很常见的apache+php+mysql的网站环境: 步骤一:安装apache sudo apt install apache2 步骤二:安装php7 1.安装PHP7和响应的 ...