-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
Bug Report for https://neetcode.io/problems/longest-substring-without-duplicates
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
I have submitted the solution for the problem "Longest Substring Without Repeating Characters".
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
if len(s) <= 1: return len(s)
longest_set = set(s[0])
cur_longest = 1
l = 0
for r in range(1, len(s)):
if s[r] == s[l]:
l += 1
else:
if s[r] not in longest_set:
longest_set.add(s[r])
cur_longest = max(cur_longest, len(longest_set))
else:
longest_set = set(s[r])
l = r
return cur_longest
The submission was accepted but the solution is incorrect (checked on leetcode). For example for the input s="ohvhjdml" proposed solution yields 5 while the correct answer is 6.

Metadata
Metadata
Assignees
Labels
No labels