package String;
public class DuplicateString {
public static boolean isDup(String s) throws Exception {
if(s==null) {
return false;
}
if(s.length() >10000){
throw new Exception("字符串长度超过10000");
}
for(int k =0;k<s.length();k++){
char c =s.charAt(k);
if(!Character.isLowerCase(c)){
throw new Exception("字符串必须全是小写字母");
}
}
int len = s.length();
for(int i =0 ;i<len;i++){
int j = i+1;
String sI = s.substring(i,i+1);
for(;j< len;j++){
String sJ = s.substring(j,j+1);
if(sI.equals(sJ)){
break;
}
}
if(j< len){
String s1 = s.substring(i,j);
String s2 = s.substring(j,2*j-i>len?len:2*j-i);
if (s1.equals(s2)) {
return true;
}
}
}
return false;
}
public static void main(String[] args) throws Exception {
String s = "abc";
System.out.println(isDup(s));
}
}