Loading...
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.
Input: s = "abcabcbb"
Output: 3
Explanation: The longest substring with all distinct characters is "abc", of length 3.
Input: s = "bbbbb"
Output: 1
Explanation: Every character is 'b', so the longest run of distinct characters is a single "b", of length 1.
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.
s.length ≤5×104s consists of English letters, digits, symbols, and spaces.Click "Run" to test with sample cases or "Submit" to run all tests.