3. 无重复字符的最长子串

This commit is contained in:
2025-09-09 23:16:54 +08:00
parent 56539bc6c1
commit 9294aed9b4

17
test008.cpp Normal file
View File

@@ -0,0 +1,17 @@
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int n = s.length();
int ret = 0;
unordered_map<char, int> count;
int l = 0;
for(int r = 0; r < n; r++){
count[s[r]]++;
while(count[s[r]] >= 2){
count[s[l++]]--;
}
ret = max(ret, r - l + 1);
}
return ret;
}
};