class Solution {
public:
int lengthOfLongestSubstring(string s) {
int i=0,j=1,k,max,n=s.size();
vector<int> a;
while(j<n){
while(s[i]!=s[j]){j++;}
k = j-i;
a.push_back(k);
i++;
}
max = *max_element(a.begin(),a.end());
return max;
}
};题目是给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
如输入: s = "abcabcbb"
输出: 3
解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。