public static int solution(String s){
int charsHash[] = new int[1000];
if(s.length()<1){
return 0 ;
}
int left = 0;
int right = 1;
int max = 1;
charsHash[(int)s.charAt(0)] = 1;
while (right<s.length()){
// 判断是否存在重复字符
if (charsHash[(int)s.charAt(right)] == 1 ){
// 左指针移到该字符的下一个位置
while(s.charAt(right) != s.charAt(left)){
charsHash[(int)s.charAt(left)] = 0;
left++;
}
//相等后再移一位
charsHash[s.charAt(left)] = 0;
left++;
}
// 计算当前长度
int tempLen = right-left+1;
if(tempLen > max){
max = tempLen;
}
// 右指针移位
charsHash[s.charAt(right)] = 1;
right++;
}
return max;
}