当前位置:网站首页>[string] determine whether S2 is the rotation string 2 of S1
[string] determine whether S2 is the rotation string 2 of S1
2022-06-12 03:00:00 【I'm not xiaohaiwa~~~~】
subject
Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring ( i.e., “waterbottle” is a rotation of “erbottlewat”).
Suppose you have a isSubstring function , You can detect whether a string is a substring of another string . Give the string s1 and s2, Use only once isSubstring Can judge s2 Whether it is s1 Rotation string for , Please write the code .
for example :”waterbottle” yes ”erbottlewat” Rotation string for .
Ideas :
It only needs get One point :s1+s1 It contains s1 All rotation strings of , So it is equivalent to judgment s2 Whether it is s1+s1 The string of .
// Judge s2 Is it right? s1 The string of
bool isSubstring(string s1, string s2){
if(s1.find(s2) != string::npos) return true;
else return false;
}
// Take precautions , And call :isSubstring(s1+s1, s2)
bool isRotation(string s1, string s2){
if(s1.length() != s2.length() || s1.length()<=0)
return false;
return isSubstring(s1+s1, s2);
}
such as :
s1 = waterbottle, A rotation string is erbottlewat
s1 + s1 = waterbottlewaterbottle
边栏推荐
- MySQL partition table create delete modify view
- Demand and business model innovation - demand 10- observation and document review
- Cupp dictionary generation tool (similar tools include crunch)
- 【点云压缩】Variational Image Compression with A Scale Hyperprior
- [digital signal processing] correlation function (energy signal | cross correlation function of energy signal | autocorrelation function of energy signal)
- Force deduction solution summary 875- coco who likes bananas
- String number with special style
- For the first time, why not choose "pure medium platform" for byte beating data platform
- Bochuang smart sprint technology innovation board: annual revenue of RMB 1.1 billion, book value of accounts receivable of RMB 300million
- Introduction to architecture - who moved my cake
猜你喜欢

errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000

Requirements and business model innovation - Requirements 7- user requirements acquisition based on use case / scenario model

架构入门讲解 - 谁动了我的蛋糕

Wechat applet project example - Fitness calculator

【点云压缩】Sparse Tensor-based Point Cloud Attribute Compression

微信小程序项目实例——体质计算器

2020-12-06
![[high code file format API] downing provides you with the file format API set Aspose, which can create, convert and operate more than 100 file formats in just a few lines of code](/img/df/f4d311308e9e76c5ae9fdc11c926b8.jpg)
[high code file format API] downing provides you with the file format API set Aspose, which can create, convert and operate more than 100 file formats in just a few lines of code

(9) Serial port interrupt

Comparison of scores
随机推荐
xml
xml
How to reduce the complexity of cloud computing infrastructure?
A single quarter of educational technology revenue of 230million: a year-on-year decrease of 51% and a sharp narrowing of net loss
Function templatesfunction templates
Using SSH public key to transfer files
安科瑞抗晃电产品在河北某化工项目的应用
2020-12-10
MySQL partition table create delete modify view
Red's deleted number
架构入门讲解 - 谁动了我的蛋糕
如何防止商場電氣火灾的發生?
Selection (045) - what is the output of the following code?
Kubernetes affinity learning notes
Bochuang smart sprint technology innovation board: annual revenue of RMB 1.1 billion, book value of accounts receivable of RMB 300million
2020-12-06
Package a mobile APK app containing watch app - ticwear
Force deduction programming problem - solution summary
Force deduction solution summary 497 random points in non overlapping rectangles
Getting started with RPC