力扣3. 无重复字符的最长子串
Posted 幽殇默
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了力扣3. 无重复字符的最长子串相关的知识,希望对你有一定的参考价值。
https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
双指针滑动窗口
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int ans=0;
map<char,int> mp;
for(int i=0,j=0;i<s.size();i++)
{
mp[s[i]]++;
while(mp[s[i]]==2)
{
mp[s[j]]--;
j++;
}
ans=max(ans,i-j+1);
}
return ans;
}
};
以上是关于力扣3. 无重复字符的最长子串的主要内容,如果未能解决你的问题,请参考以下文章