#LeetCode 003 JAVA
//滑动窗口
class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
int first = 0;
int max = 0;
int i = 0;
for(; i<s.length(); i++) {
if(!map.containsKey(s.charAt(i))) {
map.put(s.charAt(i),i);
}
else {
if(map.get(s.charAt(i)) >= first) {
max = i - first > max? i - first: max;
first = map.get(s.charAt(i)) + 1;
}
map.put(s.charAt(i),i);
}
}
if(i-first>max) {
max = i - first;
}
return max;
}
}