最长不含重复字符的子字符串
目录
1. 题目
请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。
|
|
2.算法
2.1.算法要点&图解
- map[key]value key不可重复,定义lastOccurred来记录每个字符的最后出现位置
- Start 记录开始的位置,遇到重复则更新start = lastI + 1
2.2 算法文字描述
最后一步更新lastOccurred[x]有两种情况
-
1.key 存在,即单词存在,更新它的最后出现位置
-
2.key不存在,即单词未出现,则新建
3.代码
|
|