问题:求给定的某一个字符串中的最长的没有重复字符的子串的长度
例如字符串s为:“abcdefgegcsgcasse”,其最长的没有重复字符的子串为“abcdefg”,长度为7
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int unrepeatedSubstring(string s)
{
bool alph[26]={0};
int sub_len =0;
const char* ss = s.c_str();
int len = strlen(ss);
if(len==0)
return 0;
for(int i=0;i<len;i++)
{
if( 0 == alph[s[i] - 'a'])
{
sub_len++;
alph[s[i] - 'a'] = 1;
}
else
break;
}
return sub_len;
}
int _tmain(int argc, _TCHAR* argv[])
{
string ss = "wfree";
int a = unrepeatedSubstring(ss);
cout<<a<<endl;
system("pause");
return 0;
}