1. 无重复字符的最长字串
滑动窗口
class Solution {
public int lengthOfLongestSubstring(String s) {
int n = s.length();
int ans = 0, l = 0;
HashMap<Character, Integer> map = new HashMap<>();
for(int i=0;i<n;i++){
if(map.containsKey(s.charAt(i))){
l = Math.max(l, map.get(s.charAt(i))+1);
}
map.put(s.charAt(i),i);
ans = Math.max(ans, i-l+1);
}
return ans;
}
}