Leetcode 3 - Longest Substring Without Repeating Characters JavaScript

Опубликовано: 03 Август 2026
на канале: Chuck's Resume
44
2

In “Longest Substring Without Repeating Characters,” we’re given a string and need to return the length of the longest substring containing only unique characters. Since substrings must be contiguous, we can’t skip characters. My approach uses the sliding window technique with two pointers, left and right, to represent the current window of characters. A Set tracks the characters in the window so duplicates can be detected quickly. As right expands the window, if a duplicate appears we shrink the window from the left by removing characters from the set until the duplicate is gone. After each step we update the longest length using right - left + 1, allowing us to solve the problem efficiently in O(n) time.

Leetcode 3: https://leetcode.com/problems/longest...

Leetcode 3 Source Code: https://github.com/Brixsta/Algorithms...