无重复的最大子串
算法思想
采用temp记录当前最大无重复的字符串,当遍历到原串中字符在temp中已出现时,便将temp的长度和前最大长度比较
代码如下:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int res = 0,n = s.length();
for(int i = 0;i < n;i++){
string temp = "";
for(int j = i;j < n;j++){
if(temp.find(s[j]) == -1){
temp += s[j];
}else{
break;
}
}
res = max(res,(int)temp.length());
}
return res;
}
};
2020年5月2日 00:20留