标签:ash else toc out ++ turn sub system bst
public static int lengthOfLongestSubstring(String s) {
char t[] = s.toCharArray();
int count = 0;
int max =0;
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
Map<Integer, Integer> map2 = new HashMap<Integer, Integer>(); //核心
for(int i =0;i<s.length();i++) {
if(map.get(t[i]-'a')==null) {
map.put(t[i]-'a',i);
map2.put(i,t[i]-'a');
count++;
if(count>max) {
max = count;
}
}else {
count = i-map.get(t[i]-'a'); //核心
System.out.println(map.get(t[i]-'a'));
int k = map.get(t[i]-'a');
int temp = -1; //核心清理
for(int j =0; j<=k ;j++) {
if(map2.get(j)!=null) {
temp = map2.get(j);
map.remove(temp);
map2.remove(j);
map.put(t[i]-'a',i);
map2.put(i,t[i]-'a');
}
temp = -1;
}
}
System.out.println(count+"---"+i+"--"+t[i]);
}
System.out.println("--------------");
return max;
}
标签:ash else toc out ++ turn sub system bst
原文地址:https://www.cnblogs.com/fyyxt/p/12110228.html