-
-
Save jason51122/6f636b270039087a41ce to your computer and use it in GitHub Desktop.
1.8 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 (e.g.,"waterbottle"is a rotation of"erbottlewat").
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
boolean checkRotation(String str1, String str2) { | |
if (str1 == null || str2 == null || str1.length() != str2.length()) { | |
return false; | |
} | |
String str = str1 + str1; | |
if (str.indexOf(str2) != -1) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment