Longest Substring Without Repeating Characters
Problem statement
Given a string s, return the length of the longest substring in which no character appears more than once.
A substring is a run of characters that are next to each other in s. Upper-case and lower-case letters are different characters, and a space is a character too. The empty string has answer 0.
Function
lengthOfLongestSubstring(s: String) → intExamples
Example 1
s = "abcabcbb"return = 3The longest stretches with no repeated character have length 3, for example abc. Any 4 characters in a row contain a repeat.
Example 2
s = "pwwkew"return = 3wke has 3 different characters. pwke is not a substring: its letters are not next to each other in s. The answer is 3.
Example 3
s = ""return = 0The empty string has only the empty substring, so the answer is 0.
Constraints
0 <= s.length <= 5 * 10^4sconsists of English letters, digits, and spaces.