class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
n = len(s)
if n == 0:
return 0
temp_set, max_len = set(), 0
start = 0
for i in range(n):
if s[i] not in temp_set:
temp_set.add(s[i])
if len(temp_set) > max_len:
max_len = len(temp_set)
else:
while s[start] != s[i]:
temp_set.remove(s[start])
start += 1
start += 1
return max_len