class Solution {
public int lengthOfLongestSubstring(String s) {
int n = s.length();
int ans = 0 ;
int left = 0;
int right = 0;
Map<Character,Integer> map = new HashMap<>();
for(;right < n; right++){
char c = s.charAt(right);
if(map.containsKey(c)){
left = Math.max(left,map.get(c)+1);
}
ans = Math.max(ans,right-left+1);
map.put(c,right);
}
return ans;
}
}