LeetCode 3. 无重复字符的最长子串
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;
}
};
有帮助的话可以点个赞,我会很开心的~