Why isnt this working? (C++)


#1
int Solution::solve(string A) {
    unordered_set<string> set;
    for(int i = 0; i<A.size(); i++){
        if(set.find(A[i]) != set.end()){
            set.erase(A[i]);
        }
        else set.insert(A[i]);
    }
    if(set.size() <= 1) return 1; //only 1 non pair left(eg. c in abbcbba)
    return 0;
}

#3

You created unordered set of string data type instead of that create unordered set of char data type.


#4

You have to check for odd and even size length differently.


#5

Works like a charm. Thank you :slight_smile: