leetcode-0003

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

class Solution {
public:
int lengthOfLongestSubstring(string s) {
set<char> t;
int res = 0, left = 0, right = 0;
while (right < s.size()) {
if (t.find(s[right]) == t.end()) {
t.insert(s[right++]);
res = max(res, (int)t.size());
} else {
t.erase(s[left++]);
}
}
return res;
}
};