Longest Substring Without Repeating Characters,longestrepeating
分享于 点击 11834 次 点评:277
Longest Substring Without Repeating Characters,longestrepeating
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.
Code:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
bool sign[256];
int ret=0;
memset(sign,0,sizeof(sign));
for(int i=0,j=0;i<s.size();i++)
{
while(sign[s[i]]==1)
{
sign[s[j]]=0;
j++;
}
sign[s[i]]=1;
ret=max(ret,i-j+1);
}
return ret;
}
};
相关文章
- 暂无相关文章
用户点评