Last active
August 29, 2015 13:56
-
-
Save mehmetbebek/9345657 to your computer and use it in GitHub Desktop.
Find If A String is Rotation of Another String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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