class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.size()==0)
return 0;
unordered_map<char,int>Hash;
int ans=1;
Hash[s[0]]=1;
int l=0,r=0;
for(r=1;r<s.size();r++)
{
Hash[s[r]]++;
while(Hash[s[r]]>1)
{
Hash[s[l]]--;
l++;
}
ans=max(ans,r-l+1);
}
return ans;
}
};
LeetCode 3
最新推荐文章于 2024-08-23 01:05:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)