Skip to content

Commit

Permalink
Fix longest substring without repeating characters by checking if the…
Browse files Browse the repository at this point in the history
… current character has been seen before in the current window, and if so, move the start of the window to be just after the last occurance
  • Loading branch information
arunsathiya committed Feb 24, 2024
1 parent abb185f commit 9cb9a1a
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ func lengthOfLongestSubstring(s string) int {
maxLength := 0
charhm := make(map[rune]int)
for end, char := range s {
if trackedIdx, found := charhm[char]; found {
if trackedIdx, found := charhm[char]; found && trackedIdx >= start {
start = trackedIdx + 1
}
charhm[char] = end
Expand Down

0 comments on commit 9cb9a1a

Please sign in to comment.