3. Longest Substring Without Repeating Characters
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
def check(start, end):
chars = defaultdict(int)
for i in range(start, end + 1):
c = s[i]
chars[c] += 1
if chars[c] > 1:
return False
return True
n = len(s)
res = 0
for start in range(n):
for end in range(start, n):
if check(start, end):
res = max(res, j - i + 1)
return resLast updated