Created
February 7, 2014 20:09
-
-
Save Jeffwan/8870775 to your computer and use it in GitHub Desktop.
Check if s2 is a rotation of s1 using only one call to isSubstring. CC150 - Arrays and Strings
This file contains hidden or 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
| package CC150.ArraysAndString; | |
| /** | |
| * Check if s2 is a rotation of s1 using only one call to isSubstring | |
| * eg: "waterbottle" is a rotation of "erbottlewat" | |
| * | |
| */ | |
| public class IsRotation { | |
| public boolean isRotation2(String s1, String s2) { | |
| // error checking | |
| if ((s1.length() != s2.length()) && (s1.length() >0)) { | |
| return false; | |
| } | |
| String newStr = s1.concat(s1); // String newStr = s1 + s1; also works | |
| return isSubstring(newStr, s2); | |
| } | |
| private boolean isSubstring(String newStr, String s2) { | |
| // TODO Auto-generated method stub | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment