LeetCode3. 无重复字符的最长子串
https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
class Solution {
public:
int lengthOfLongestSubstring(string s) {
s = " " + s;
int i = 1;
int j = 1;
int vis[300] = { 0 };
int ans = 0;
for (; j < s.size(); j++) {
if (vis[s[j]]) {
for (; i <= vis[s[j]]; i++) {
vis[s[i]] = 0;
}
}
vis[s[j]] = j;
ans = max(ans, j - i + 1);
}
return ans;
}
};