determine if a string has all unique characters?

前端 未结 16 1490
长发绾君心
长发绾君心 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:21

    #include 
    #include 
    using namespace std;
    
    bool isUnique(string _str)
    {
            bool char_set[256];
            int len = _str.length();
    
            memset(char_set, '\0', 256);
            for(int i = 0; i < len; ++i)
            {
                int val = _str[i]- '0';
                if(char_set[val])
                {
                    return false;
                }
                char_set[val] = true;
            }
    
            return true;
        }
    
        int main()
        {
            cout<<"Value: "<

提交回复
热议问题