这个题我们使用滑动窗口技巧来解题。
class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> windows = new HashMap();
int left = 0;
int right = 0;
int res = 0;
while(right < s.length()){
char c = s.charAt(right);
right++;
window.put(c, window.getOrDefault(c, 0) + 1);
while(window.get(c) > 1)){
char d = s.charAt(left);
left++;
window.put(d, window.getOrDefault(d, 1) - 1);
}
res = res > (right - left) ? res : (right - left);
}
return res;
}
}