Check if a string is a rotation of another
Given two strings, check if string 2 is a rotation of string1.
string1: hello
string2: olhel
returns: true
- Check if strings are of equal length
- Combine string1 with string1
- See if string 2 is within string1
bool isRotation(string str1, string str2) {
if(str1.length() != str2.length()) {
return false;
}
str1.append(str1);
if(str1.find(str2) != std::string::npos) {
return true;
}
return false;
}