```
def lengthOfLongestSubstring(self, s):
mx = i = j = 0
chars = {}
while i < len(s):
if chars.get(s[i],0) > 0: #shrinking so no need to check for max length
chars[s[j]] -= 1
j += 1
else:
mx = max(mx, i - j + 1)
chars[s[i]], i = 1, i + 1
return mx
```