Mar 02, 2024
3. Longest Substring Without Repeating Characters
Given a string s, find the length of the longest substring without repeating characters.
Solution 1
1 | class Solution { |
通过哈希表存储字符值对应的下一个索引位置,i-j维持着不重复字符序列的左右两边。一旦右索引检测到哈希表中存在某值的下一个索引且这个索引位置大于序列左边的索引,则将左边向右移到哈希表存储的值的位置,变窄。