题解 | #最长不含重复字符的子字符串#
最长不含重复字符的子字符串
https://www.nowcoder.com/practice/48d2ff79b8564c40a50fa79f9d5fa9c7
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int maxlen = 0;
unordered_map<char, int> map;
for (int left = 0, right = 0; right < s.size(); ++right){
map[ s[right] ]++;
// 此字符重复
while (map[ s[right] ] > 1)
map[ s[left++] ]--;
maxlen = max(maxlen, right - left + 1);
}
return maxlen;
}
};


上海得物信息集团有限公司公司福利 1166人发布