class Solution {
public:
int lengthOfLongestSubstring(string s) {
vector<int> cnt(128, 0);
int first = 0, size = s.size(), maxSize = 0;
for (int i = 0; i < size; i++) {
cnt[s[i]]++;
if (cnt[s[i]] > 1) {
//重要: 將first移動到第一個重複字出現的下一個字母
for (; s[first] != s[i]; first++) {
cnt[s[first]] = 0;
}
first++;
}
maxSize = max(i - first + 1, maxSize);
}
return maxSize;
}
};