determine if a string has all unique characters?

前端 未结 16 1416
长发绾君心
长发绾君心 2020-12-28 08:29

Can anybody tell me how to implement a program to check a string contains all unique chars ?

16条回答
  •  情话喂你
    2020-12-28 09:33

    Without using additional memory:

    #define UNIQUE_ARRAY 1
    int isUniqueArray(char* string){
        if(NULL == string ) return ! UNIQUE_ARRAY;
        char* current = string;
        while(*current){
            char* next   = current+1;
            while(*next){
                if(*next == *current){
                    return ! UNIQUE_ARRAY;
                }
                next++;
            }
            current++;
        }
        return UNIQUE_ARRAY;
    }
    

提交回复
热议问题