输入一个字符串,输出该字符串去除重复字符后所得字符串的长度
比如:输入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);
}
推荐阅读
- 一个人的旅行,三亚
- 一个小故事,我的思考。
- 一个人的碎碎念
- 七年之痒之后
- 我从来不做坏事
- 异地恋中,逐渐适应一个人到底意味着什么()
- 迷失的世界(二十七)
- live|live to inspire 一个普通上班族的流水账0723
- 遗憾是生活的常态,但孝顺这件事,我希望每一个人都不留遗憾
- NO.38|NO.38 我不是嫁不出去,而是不想嫁