【滑动窗口】016. 不含重复字符的最长子字符串
题目链接:https://leetcode-cn.com/problems/wtcaE1/
class Solution {
public:
int lengthOfLongestSubstring(string s)
{
map<char,int> cntMap;
int max = 0;
queue<char> que;
for (size_t i = 0; i < s.length(); i++) {
int index = s[i] - 'a';
cntMap[index]++;
que.push(s[i]);
while (cntMap[index] > 1) {
char top = que.front();
que.pop();
cntMap[top - 'a']--;
}
max = que.size() > max ? que.size() : max;
}
return max;
}
};
浙公网安备 33010602011771号