Skip to content

Instantly share code, notes, and snippets.

@jyhjuzi
Created June 26, 2014 22:47
Show Gist options
  • Save jyhjuzi/1b818b85eeff95152460 to your computer and use it in GitHub Desktop.
Save jyhjuzi/1b818b85eeff95152460 to your computer and use it in GitHub Desktop.
public class Q1_8{
public static void main(String args[]){
String test1 = "test";
String test2 = "estt";
System.out.println(isRotation(test1, test2));
}
private static boolean isRotation(String s1, String s2){
if(s1.length() != s2.length())
return false;
String s= s2+s2;
if(isSubstring(s1,s))
return true;
else return false;
}
private static boolean isSubstring(String s1, String s2){
if(s1.length()> s2.length())
return false;
for(int i = 0; i<=s2.length()-s1.length(); i++){
if(s2.substring(i,i+s1.length()).equals(s1))
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment