当前位置:网站首页>面试题 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
边栏推荐
- 力挺吴雄昂!Arm中国管理层发公开信:对莫须有的指控感到震惊和愤怒!
- I want to get 20K after 3 years of experience, but I haven't got it for half a month?
- Gossip: an initially perfect FS is as impractical as the first version of the program requiring no bugs
- How to make digital retail undertake the development task of the era of traffic and retention may be the key
- Basic learning of cesium
- Cesium add light sweep
- 8000 word explanation of OBSA principle and application practice
- The cooperation between starfish OS and metabell is just the beginning
- Focus loss explanation
- Adding custom dynamic arts and Sciences to cesium
猜你喜欢

Basic concept and classification of i/o equipment

Fluent call interface UI

杂谈:一份最初就非常完善的FS跟第一版程序就要求没bug一样不切实际

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

Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24

idea常用的快捷键汇总

EWM receiving ECC delivery note verification logic problem

Cesium add dynamic pop-up

Flutter 通话界面UI

在一个字符串里面统计给定字符串的个数
随机推荐
Lua进阶
彻底搞懂kubernetes调度框架与插件
Day 013 一维数组练习
At the meeting on June 19, SMIC may set the fastest listing record in China!
Gazebo control example
彻底搞懂kubernetes调度框架与插件
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
JUC concurrent programming learning
Cesium add inundation analysis measurement area
Lecture 16 of project practice: using the open close principle to realize the commodity price rule engine
华米科技“黄山2号”发布:AI性能提升7倍,功耗降低50%!
Basic concept and classification of i/o equipment
Cross domain requests in nodejs
晶方科技:光刻机厂商ASML为公司参与并购的Anteryon公司的最主要客户之一
EWM receiving ECC delivery note verification logic problem
Gossip: an initially perfect FS is as impractical as the first version of the program requiring no bugs
JG-数据重置(wd)
Kibana6.2.4 version update x-pack certification
Learn how Baidu PaddlePaddle easydl realizes automatic animal recognition in aquarium
Byte monthly salary 28K, share a wave of my automation testing experience