Longest Substring Without Repeating Characters
下面是 LeetCode 原题
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3.
Note that the answer must be a substring, "pwke" is a subsequenc eand not a substring.
之前做过最小子串覆盖,感觉应该是类似的问题。需要的子串是一长串不重复的,不包含所有出现过的字符也是很正常的。同样是一个头指针,一个尾指针,found每次只存当前子串访问过的字符。每发现任意重复字符,截止该字符之前的部分即为一个子串。重置到重复字符之前的所有found为否,这里要用到Hash来做字符到索引的映射(false, 0 ... 根据实现),并确保该重复字符是已发现状态,开始寻找下一个无重复子串。
后来看了一下,有个关于这类问题的解题关键字:滑动窗口,Sliding Window。