1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map<char,int> mp;
int res = 0;
for(int i = 0, j = 0; i < s.size(); i ++){
mp[s[i]] ++;
while(mp[s[i]] > 1){
mp[s[j]] --;
j ++;
}
res = max(res, i - j + 1);
}
return res;
}
};