Longest Substring Without Repeating Characters
Problem statement
Given a string s, return the length of its longest contiguous substring with no repeated character. Character comparisons are case-sensitive. A substring must use consecutive characters; a subsequence does not qualify. Return 0 for the empty string.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "abcabcbb"return = 3abc is a valid substring of length 3. Every substring of length 4 contains a repeated character.
Example 2
s = "bbbbb"return = 1A single b is valid. Every longer substring repeats b.
Example 3
s = ""return = 0The empty string has no characters, so the longest length is 0.
Constraints
0 <= s.length <= 100000.- Every character in
sis printable ASCII, with a character code from 32 through 126.