LeetCode 3. 无重复字符的最长子串

穿过雾的阴霾 / 2023-08-05 / 原文

class Solution {
public:
    int res=0;
    int lengthOfLongestSubstring(string s) {
        int n=s.size ();
        if(!n)  return 0;
        bool st[128]={false};
        for(int j=0,i=0;j<n;j++)
        {
            while(j&&st[s[j]]==true)//该字符是重复字符
                st[s[i++]]=false;
            st[s[j]]=true;
            res=max(res,j-i);
        }
        return res+1;
    }
};