25. Longest Substring Without Repeating Characters
MediumStrings~25 min
Return the length of the longest substring that contains no repeated characters.
A substring is a contiguous stretch of the string — the characters must be next to each other.
Examples
Example 1
- Input:
- str = "abcabcbb"
- Output:
- 3
- Why:
- "abc" is the longest stretch with no repeats.
Example 2
- Input:
- str = "bbbbb"
- Output:
- 1
Example 3
- Input:
- str = "pwwkew"
- Output:
- 3
- Why:
- "wke" — note that "pwke" is not contiguous.
Constraints
0 <= str.length <= 5000The string may contain letters, digits, symbols and spaces.