按理说应该能这题2分法应该能AC,但不知道为何会超时。。。
import java.util.*;
public class Main{
static String p;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
p = sc.nextLine();
int n = p.length();
int l = 0,r = n;
while (l < r){
int mid = (l+r+1)/2;
if(check(mid)){
l = mid;
}else{
r = mid-1;
}
}
System.out.println(l);
}
public static boolean check(int j){
for(int i = 0;i<p.length()-j+1;i++){
String sq = p.substring(i,j+i);
if(p.indexOf(sq,i+1) != -1){
return true;
}
}
return false;
}
}