Skip to content

Instantly share code, notes, and snippets.

@mehmetbebek
Last active August 29, 2015 13:56
Show Gist options
  • Save mehmetbebek/9345657 to your computer and use it in GitHub Desktop.
Save mehmetbebek/9345657 to your computer and use it in GitHub Desktop.
Find If A String is Rotation of Another String
/* algorithm checkRotation(string s1, string s2)
if( len(s1) != len(s2))
return false
if( substring(s2,concat(s1,s1))
return true
return false
end */
//In Java:
boolean isRotation(String s1,String s2) {
return (s1.length() == s2.length()) && ((s1+s1).indexOf(s2) != -1);
}
Hello. When i was searching a portal find a good interview question. There is answer of that question.
Question:
There are two String string1 and string2. how can you check if string1 is a rotated version of string2.
Example:
If string1 = "github" then the following are some of its rotated versions:
"ithubg"
"hubgit"
but "githbu" is not a rotated version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment