输入一个字符串,输出该字符串去除重复字符后所得字符串的长度

比如:输入ababdedea
【输入一个字符串,输出该字符串去除重复字符后所得字符串的长度】返回4
输入hijkj
返回4
bool tem_in_s1(char e,char * str,int size)
{
int i;
for (i = 0; i < size; i++)
{
if (e == *(str + i))
return true;
}
return false;
}
int lengthOfLongestSubstring(char* s) {
char s1[1024];
int length, length1;
char tem;
int i;
bool ret;
s1[0] = s[0];
s1[1] = '\0';
length = strlen(s);
length1 = strlen(s1);
printf("length:%d,length1:%d\n", length, length1);
for (i = 0; i < length; i++)
{
tem = *(s + i);
ret = tem_in_s1(tem, s1, length1);
if (!ret)
{
*(s1 + length1) = tem;
*(s1 + length1 + 1) = '\0';
length1++;
}
}
return strlen(s1);
}


    推荐阅读