Skip to content

Instantly share code, notes, and snippets.

@Jeffwan
Created February 7, 2014 20:09
Show Gist options
  • Select an option

  • Save Jeffwan/8870775 to your computer and use it in GitHub Desktop.

Select an option

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
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