Problem · String
Longest Substring Without Repeating Characters
Learn this problemProblem statement
Given a string text, return the length of its longest contiguous substring whose characters are all distinct.
The empty string has answer 0.
Function
lengthOfLongestSubstring(text: String) → intExamples
Example 1
text = "abcabcbb"return = 3abc is a longest substring with no repeated character.
Example 2
text = "pwwkew"return = 3wke has length three. The answer concerns a contiguous substring, not a subsequence.
Constraints
0 <= text.length() <= 100000textcontains only printable ASCII characters.