class Solution {
public:
int maxFun(int a, int b)
{
return a > b ? a : b;
}
int lengthOfLongestSubstring(string s) {
int n = s.size();
if (n < 2)
{
return n;
}
int left = 0, right = 0;
unordered_set<char> charset;
int max_len = -1;
while (right < n)
{
while (charset.find(s[right]) != charset.end())
{
charset.erase(s[left++]);
}
charset.insert(s[right]);
max_len = maxFun(max_len, right - left + 1);
right++;
}
return max_len;
}
};
LeetCode剑指 Offer 48. 最长不含重复字符的子字符串
最新推荐文章于 2023-08-27 15:23:10 发布