Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int i = 0,j,maxx = 0;
int findd[128];
memset(findd,0,sizeof(findd));
for(j = 0;j < s.length();j ++){
while(findd[s[j]] == 1){
findd[s[i]] = 0;
i ++;
}
findd[s[j]] = 1;
maxx = max(maxx,j - i + 1);
}
return maxx;
}
};
本文介绍了一种算法,用于找到给定字符串中最长的无重复字符子串。通过遍历字符串并使用查找表来跟踪字符出现情况,实现算法以高效地计算最长子串长度。
697

被折叠的 条评论
为什么被折叠?



