最长无重复字符串
class Solution {
public int lengthOfLongestSubstring(String s) {
if(s==null || s.length()==0)
return 0 ;
Map<Character,Integer> map = new HashMap<>();
int longest = 0;
int tempStart = 0;
for(int i = 0;i < s.length();i++){
char c = s.charAt(i);
int distance = 0;
if(map.containsKey(c)){
distance = tempStart > map.get(c) ? i-tempStart+1 : i-map.get(c);
tempStart = Math.max(map.get(c)+1,tempStart);
}else{
distance = i - tempStart +1;
}
map.put(c,i);
longest = Math.max(longest,distance);
}
return longest;
}
}