classSolution{
publicintlengthOfLongestSubstring(String s){
int ans =0;int now =0;int st =0;
Map<Character, Integer> mp =newHashMap<>();for(int i =0; i < s.length(); i++){
char ch = s.charAt(i);if(mp.getOrDefault(ch,-1)< st){
now++;}else{
int fin = mp.get(ch);
now -= fin - st;
st = fin +1;}
mp.put(ch, i);
ans = Math.max(ans, now);}return ans;}}