LeetCode OJ Longest Substring Without Repeating Characters 不重复的最长字串 滑动窗口,leetcoderepeating
分享于 点击 47858 次 点评:201
LeetCode OJ Longest Substring Without Repeating Characters 不重复的最长字串 滑动窗口,leetcoderepeating
Longest Substring Without Repeating Characters
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 has[256];
memset(has,-1,sizeof(has));
int i,id=-1,max=0;
for(i=0;i<s.size();i++){
if(has[s[i]]>id)
{
id=has[s[i]];
}
if(i-id>max)
{
max=i-id;
}
has[s[i]]=i;
}
return max;
}
};
相关文章
- 暂无相关文章
用户点评