统计一个字符串中不重复的字符串的最大长度

统计一个字符串中不重复的字符串的最大长度

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
int get_maxlen(char *s)
{
    int a[128]={0};
    int b=0,left=0;
    int max=0;
    while(b<strlen(s))
    {
        if(a[s[b]]>0)
        {
            a[s[left]=0];
            left++;
        }
        else
        {
            a[s[b]]=1;
            b++;
            max=(b-left)>max?(b-left):max;
        }
    }
    return max;
}
int main()
{
    char a[128]={0};
    printf("input >>");
    scanf("%s",a);
    printf("%d\n",get_maxlen(a));
    return 0;
}

posted on 2023-05-31 20:48  wessf  阅读(17)  评论(0)    收藏  举报