Skip to content

Instantly share code, notes, and snippets.

@aliang228
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliang228/a30904b8e80568181e2f to your computer and use it in GitHub Desktop.
Save aliang228/a30904b8e80568181e2f to your computer and use it in GitHub Desktop.
判断两个字符串是否是回环变位
/**
* Created by a598799539 on 15-7-2.
* github: https://github.com/a598799539
*/
public class Test {
public static void main(String[] args){
String string1 = "ACAT";
String string2 = "TACA";
isCircleRotation(string1,string2);
}
//判断两个字符串是否是回环变位
public static boolean isCircleRotation(String string1, String string2){
int index = string1.indexOf(string2.substring(0,2));
String rot;
if(index == -1){
rot = string1.substring(string1.length()-1) + string1.substring(0,string1.length()-1);
}else{
rot = string1.substring(index) + string1.substring(0,index);
}
if(rot.equals(string2)){
return true;
}else{
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment