Skip to content
CodeShare
All problems

Longest Substring Without Repeats

Find the longest stretch of text with no repeated character.

MediumStringsSliding windowHash map

Given a string s, return the length of the longest substring that contains no repeated characters.

A substring is a contiguous run of characters within the string.

Examples

Example 1
Input
s = "abcabcbb"
Output
3
Why
"abc" is the longest run without repeats.
Example 2
Input
s = "bbbbb"
Output
1
Example 3
Input
s = "pwwkew"
Output
3
Why
"wke" has length 3.

Constraints

  • 0 <= s.length <= 5 * 10^4
  • s may contain letters, digits, symbols and spaces.