当前位置:网站首页>面试题 01.09. 字符串轮转
面试题 01.09. 字符串轮转
2022-07-27 23:29:00 【欢迎来到对抗路】
题目要求:
字符串轮转。给定两个字符串s1和s2,请编写代码检查s2是否为s1旋转而成(比如,waterbottle是erbottlewat旋转后的字符串)。
题目理解:
旋转的本质就是将一个字符串拆分成两个子字符串然后重新组合看是否满足另一个字符串,等价于两倍字符串。
示例1:
输入:s1 = "waterbottle", s2 = "erbottlewat"
输出:True
示例2:
输入:s1 = "aa", s2 = "aba"
输出:False
class Solution {
public:
bool isFlipedString(string s1, string s2) {
if(s1.size() != s2.size())
return false;
string s = s2 + s2;
int a = s.find(s1);
if(a!=-1)
return true;
else
return false;
}
};
心得体会:
string s1="zzabc";
s1.find("abc")
若找到则返回下位标,未找到则返回-1
边栏推荐
- Codeforces暑期训练周报(7.21~7.27)
- BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)
- Briefly understand namenode and datanode
- 力挺吴雄昂!Arm中国管理层发公开信:对莫须有的指控感到震惊和愤怒!
- From functional testing to automated testing, my monthly salary has exceeded 30k+, and I have 6 years of testing experience.
- URDF integrated gazebo
- Basic concept and classification of i/o equipment
- idea常用的快捷键汇总
- Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24
- 开发 Flutter 录音功能的插件
猜你喜欢

Knowledge of two-dimensional array

LeetCode 2341. 数组能形成多少数对

idea常用的快捷键汇总

Codeforces暑期训练周报(7.21~7.27)

LeetCode 2347. 最好的扑克手牌

Harmonyos 3 was officially released: Hongmeng mobile phones are smooth and safe, and Hongmeng terminals are often used

Oxygen temperature and humidity module

Unity Shader入门精要学习——基础纹理

彻底搞懂kubernetes调度框架与插件

“蔚来杯“2022牛客暑期多校训练营3 补题题解(A、C、J)
随机推荐
S-RPN: Sampling-balanced region proposal network for small crop pest detection
闻泰科技收购安世半导体剩余股权获得无条件通过
C language main function transfer parameters
MySQL JPA support for JSON type data in database
Wentai technology acquired the remaining equity of ANSYS semiconductor and obtained unconditional approval
ABAP CDS Table Function介绍与示例
Transplant QT system for i.mx6ull development board - cross compile QT code
二维数组相关知识
JG-数据重置(wd)
Principle of logistic regression
From functional testing to automated testing, my monthly salary has exceeded 30k+, and I have 6 years of testing experience.
实现ABCD字母递增
华米科技“黄山2号”发布:AI性能提升7倍,功耗降低50%!
Flutter 通话界面UI
Lua get started quickly
【游戏】任天堂Nintendo Switch超详细购买/使用指南以及注意事项(根据自己使用持续更新中...)
EWM receiving ECC delivery note verification logic problem
Codeforces summer training weekly (7.21~7.27)
糟糕程序员的20个坏习惯
URDF 集成 Gazebo