//给定一个字符串,求出其最长的重复子串。
public class Longest { public static void main(String args[]) {
String str = "bbbaaaac";

int maxLengthValue=0;
int start=0,end=0;

for (int i = 0; i < str.length(); i++) {
for (int j = i + 1; j < str.length();) {
while (str.charAt(i) == str.charAt(j)) {

if(j-i+1>maxLengthValue){
maxLengthValue=j-i+1;
start=i;end=j;
}
j++;
}
break;
}
}


System.out.println(start+" "+end); }
}



import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;//给定一个字符串,求出其最长的重复子串。
public class Longest { public static void main(String args[]) {
String str = "bcdabcdaaa";
Set<String> temp = new HashSet<String>();
List<String> result = new ArrayList<String>(); for (int i = 0; i < str.length(); i++) {
for (int j = i; j <= str.length(); j++) { // 注意这个<= if (!temp.add(str.substring(i, j))) {
result.add(str.substring(i, j));
} }
} int maxValue = 0;
int maxNum = 0;
for (int i = 0; i < result.size(); i++) {
if (result.get(i).length() > maxValue) {
maxValue = result.get(i).length();
maxNum = i;
}
} System.out.println(result.get(maxNum));
}}