Longest Substring Without Repeating Characters
Given a string s, return the length of the longest contiguous substring that contains no repeated characters.
A substring is a run of consecutive characters from s (not a subsequence). The answer is a single number — the length of the longest such run — not the substring itself.
Example cases
- repeat resets windowin s = "abcabcbb"out 3The longest run without a repeat is `abc`, length 3.
- all samein s = "bbbbb"out 1Every character is `b`, so the longest run is a single `b`.
- repeat in the middlein s = "pwwkew"out 3`wke` has length 3. `pwke` is not a substring (the characters aren't consecutive).
- empty stringin s = ""out 0An empty string has no characters, so the length is 0.
Constraints
- 0 <= s.length <= 5 * 10^4
- `s` consists of English letters, digits, symbols, and spaces.
s =
"abcabcbb"