class Solution {
public:
int lengthOfLongestSubstring(string s) {
map<int,int> m;
int slow = 0;
int fast = 0;
int ma = 1;
int n = s.size();
if(n==0) return 0;
while(fast<n)
{
if(m.find(s[fast])==m.end())
{
m[s[fast]] = s[fast];
fast++;
}
else
{
slow++;
fast = slow;
m.clear();
}
ma = max(ma,fast-slow);
}
return ma;
}
};
leetcode每日一题第三十一天
最新推荐文章于 2024-11-04 12:20:00 发布