Problem Statement
How do you check if one string is a rotation of another?
Explanation
Concatenate the first string with itself. If the second string appears as a substring in this concatenated string, it is a rotation. For example, 'erbottlewat' is a rotation of 'waterbottle'. This works in O(n) time with efficient substring search.
Code Solution
SolutionRead Only
boolean isRotation(String s1,String s2){
if(s1.length()!=s2.length()) return false;
String concat=s1+s1;
return concat.contains(s2); }
// waterbottle + waterbottle -> contains erbottlewatPractice Sets
This question appears in the following practice sets:
