public static int lengthOfLongestSubstring(String s) {
if(s==null||s.length()==0)return 0;
int[] t = new int[256];
int start =0;
int end = 0;
int max = 0;
int beg = 0;
int e = 0;
Arrays.fill(t, -1);
char[] ch = s.toCharArray();
int len = ch.length;
for(int i=0;i<len;i++){
if(t[ch[i]]!=-1){
while(start<=t[ch[i]]){
t[ch[start++]] =-1;
}
}
t[ch[i]] = i;
if(i-start+1>max){
beg = start;
e= i;
max = i-start+1;
}
}
System.out.println("beg="+beg+",end="+e);
System.out.println(s.substring(beg, e+1));
return max;
}
最长不重复子串
最新推荐文章于 2024-02-03 12:13:58 发布