算法1 双指针 滑动窗口 哈希表
C++ 代码
class Solution {
public:
int lengthOfLongestSubstring(string s)
{
unordered_map<char,int>heap;
int res = 0;//存储最大长度
for(int i = 0,j = 0;j<s.size();j++)
{
heap[s[j]]++;
while(heap[s[j]]>1) heap[s[i++]]--;
res = max(res,j-i+1);
}
return res;
}
};