题目链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
题目描述:
题解:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.size() < 2)
return s.size();
unordered_set<char> window;
int maxLen = 0;
int left = 0;
for(char i = 0; i < s.size(); i++)
{
while(window.find(s[i]) != window.end())
{
window.erase(s[left]);
left++;
}
maxLen = max(maxLen, i - left + 1);
window.insert(s[i]);
}
return maxLen;
}
};