3. 无重复字符的最长子串
This commit is contained in:
17
test008.cpp
Normal file
17
test008.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user