/*
双指针算法
*/
class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> hashMap = new HashMap<>();
char[] chars = s.toCharArray();
int res = 0;
int l = 0, r = 0;
while (r < chars.length) {
while (hashMap.containsKey(chars[r])) hashMap.remove(chars[l ++]);
hashMap.put(chars[r], 1);
res = Math.max(res, r - l + 1);
r ++;
}
return res;
}
}