leetCode(longest-substring-without-repeating-characters)-最长不重复子串

题目:给定一个字符串,找到该字符串中最长的不重复字串,并输出其长度。

思路:

解法一:可以枚举排列该字符串的所有字串,找到其中最长的。

解法二:使用HashMap保存已经遍历过的字符的索引,维护一个start,采用一次遍历的方式找出最长的子串

解法三:由于考虑到解法二中的HashMap中的key是字符,可以直接简化HashMap为一个256长度的数组,字符的ascii码作为key,这样可以减少hash冲突的解决时间

leetCode(longest-substring-without-repeating-characters)-最长不重复子串

leetCode(longest-substring-without-repeating-characters)-最长不重复子串

leetCode(longest-substring-without-repeating-characters)-最长不重复子串