java实现无重复最长字符串
public int lengthOfLongestSubstring(String s) {
if(s.length()==0){
return 0;
}
HashMap<Character,Integer> mymap=new HashMap<Character,Integer>();
int i=0;
int lentag=1;
int [] dp=new int[s.length()];
dp[0]=1;
mymap.put(s.charAt(i),i);
for(i=1;i<s.length();i++){
if(!mymap.containsKey(s.charAt(i))){
dp[i]=dp[i-1]+1;
mymap.put(s.charAt(i),i);
lentag=dp[i]>lentag?dp[i]:lentag;
}else{
i=mymap.get(s.charAt(i))+1;
dp[i]=1;
mymap=new HashMap<Character,Integer>();
mymap.put(s.charAt(i),i);
lentag=dp[i]>lentag?dp[i]:lentag;
}
}
return lentag;
}