classSolution:deflengthOfLongestSubstring(self, s:str)->int:if s =='':
m =0return m
hash_map ={}
len_arr =[1for i inrange(len(s))]
m =1for index, val inenumerate(s):ifnot val in hash_map:if index !=0:
len_arr[index]= len_arr[index -1]+1else:if(hash_map[s[index -1]]- len_arr[index -1]+1)<= hash_map[val]:
len_arr[index]= hash_map[s[index -1]]- hash_map[val]+1else:
len_arr[index]= len_arr[index -1]+1
m = len_arr[index]if len_arr[index]>= m else m
hash_map[val]= index
return m