剑指offer-最长不含重复字符的子字符串
2020-04-19 本文已影响0人
棉花糖7
在记录一遍,自己已经做过一遍的题目
奈何还是记不住
这是一道滑动窗口的题目,同事利用了哈希表map来记录出现过的字符的位置
最重要的一句,就是当map中出现过字符时,怎么更新left的值
left = max(left,mp[s[right]]+1);//这句是难点
因为有可能出现 "abba" 这种字符串,所以 不能 直接left = mp[s[right]]+1
当 left = 3时,mp[s[left]] +1=0+1=1; 小于 现在left的值,当前 left = 2,所以应该取大值left = max(left,mp[s[right]]+1)

