Longest Substring Without Repeating Characters
Last updated
Last updated
Given a string s
, find the length of the longest
substringwithout repeating characters.
Example 1:
Example 2:
Example 3:
Constraints:
0 <= s.length <= 5 * 104
s
consists of English letters, digits, symbols and spaces.
You can solve this problem using the sliding window technique in JavaScript. Here's a possible implementation:
This function lengthOfLongestSubstring
iterates through the string s
using two pointers, left
and right
, to define a sliding window. It maintains a map charMap
to store the most recent index of each character encountered. If a character is encountered again within the current substring, the left pointer is moved to the right of its last occurrence. Finally, the function returns the maximum length found.