标签:ges http problem with max 题目 rac ble bst
c++
class Solution {
public:
map<char,int> m;
int a[100005];
int lengthOfLongestSubstring(string s) {
int len = s.length();
if(len==0)
return 0;
a[0]=1;
m[s[0]]=1;
int mm=1;
for(int i=1;i<len;i++)
{
if(m[s[i]]==0)
{
a[i]=a[i-1]+1;
mm = max(mm,a[i]);
m[s[i]]=i+1;
}
else
{
if(m[s[i]]-1>=i-a[i-1])
{
a[i]=i-m[s[i]]+1;
}
else
a[i]=a[i-1]+1;
mm = max(mm,a[i]);
m[s[i]]=i+1;
}
}
return mm;
}
};
LeetCode 3 Longest Substring Without Repeating Characters
标签:ges http problem with max 题目 rac ble bst
原文地址:https://www.cnblogs.com/dacc123/p/10941718.html