leetcode3:不重复的最长子串长度

package hashmap;

import java.util.HashMap;
import java.util.Map; public class hashmap { public static void main(String[] args) {
String s="dvdf";
if(s==null||s.length()==0){
System.out.println("null");
}
int result=1;
Map<Character,Integer> charIndexMap= new HashMap<>();
int[] length = new int[s.length()];
int lastDuplicate = 0;
length[0]=1;
charIndexMap.put(s.charAt(0),0); for(int i=1;i<s.length();i++){
Character ch = s.charAt(i);
if(charIndexMap.containsKey(ch)){
length[i]=i-Math.max(charIndexMap.get(s.charAt(i)),lastDuplicate);
lastDuplicate = Math.max(lastDuplicate, charIndexMap.get(s.charAt(i)));
}
else{
length[i]=length[i-1]+1;
}
charIndexMap.put(ch,i);
result = Math.max(result,length[i]);
}
System.out.println(result); } }
上一篇:AVD模拟器运行异常


下一篇:修改oracle字符集