class Solution {
public:
int lengthOfLongestSubstring(string s) {
int n = s.length();
vector<int> last(256, -1);
int res = 0;
for (int left = 0, right = 0; right < n; right++) {
left = max(left, last[s[right]] + 1);
res = max(res, right - left + 1);
last[s[right]] = right;
}
return res;
}
};