Given a string s, return the length of the longest contiguous substring of s in which every character is distinct (no character repeats within the substring).
A substring is a run of consecutive characters; the empty string has no characters and its answer is 0.
Examples
Example 1
Input: s = "abcabcbb"
Output: 3
Explanation: The longest substring with all distinct characters is "abc", of length 3.
Example 2
Input: s = "bbbbb"
Output: 1
Explanation: Every character is 'b', so the longest run of distinct characters is a single "b", of length 1.
Example 3
Input: s = "pwwkew"
Output: 3
Explanation: The longest substring with all distinct characters is "wke", of length 3. Note that "pwke" is a subsequence, not a substring, and so does not count.
Constraints
0≤s.length≤5×104
s consists of English letters, digits, symbols, and spaces.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up