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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int c[26];
int count=0;
int max=0;
int begin=0;
memset(c,0,sizeof(int)*26);
for(int i=0 ; i<s.length() ; i++){
int index=s[i]-'a';
if(c[index]==0 || c[index]>0 && c[index]<begin)
c[index]=i+1;else {//if(c[index]>0 && c[index]>=begin){
if(i-begin>max)
max=i-begin;
begin=c[index];
c[index]=i+1;
}
}
if(s.length()-begin>max)
max=s.length()-begin;
return max;
}
};