Files
leetcode-hot100/test008.cpp

17 lines
402 B
C++

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;
}
};