public class MainTest {
/**
* @param args
*/
public static void main(String[] args) {
String[]ss = {"","a","ab","abc","abcbba","abcdefgabc","abcdabcdef"};
for(String s : ss){
System.out.println("s = " + s + "; noReapLength = " + maxStringNoRepeatLength(s));
}
}
public static int maxStringNoRepeatLength(String s){
if(s == null || s.length() == 0){return 0;}
int start = 0;
int maxLength = 1;
for(int end = start + 1;end <= s.length() - 1;end++){
int index = end - 1;
int tempLength = 0;
while(index >= start){
if(s.charAt(index) != s.charAt(end)){
index--;
}else{
break;
}
}
tempLength = end - start + 1;
if(index >= start){
start = index + 1;
tempLength -= 1;
}
if(tempLength > maxLength){
maxLength = tempLength;
}
}
return maxLength;
}
}