class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
length = len(s)
if length <= 1:
return length
newlist = [1]
maxa = 1
hashdict = {s[0]:0}
for i in range(1,length):
this = s[i]
if this in hashdict and hashdict[this] != length:
old = hashdict[this]
newlist.append(i - old)
for key in hashdict:
if hashdict[key] < old:
hashdict[key] = length
hashdict[this] = i
else:
hashdict[this] = i
newlist.append(newlist[-1] + 1)
maxa = max(newlist[-1],maxa)
return maxa