Total Difference Strings
Give a string list to determine how many different strings are returned with the same number of definitions: string lengths are equal and left to right, or right to left are the same characters as ABC and CBA are considered the same.
A "hash table" is used to store strings, which are completed in the time complexity of O (N).
#include <string>#include<iostream>#include<algorithm>#include<initializer_list>#include<unordered_map>using namespacestd;classsolution{ Public: Solution (Constinitializer_list<string> &il) {strings; for(initializer_list<string>::iterator it = Il.begin (); It! = Il.end (); it++) {s= *it; Reverse (S.begin (), S.end ()); S= This->_sort (*it, s); M[s]++; }} size_t Gettotaldifferencestringnumber () {return This-m.size ();}Private: string_sort (Const string& LHS,Const string&RHS) { if(LHS >RHS)returnRHS +LHS; Else returnLHS +RHS; } unordered_map<string, unsigned> m = {};};intMain () {solution SO ({"ABC","CBA","Aaa","ABC"} ); cout<<So.gettotaldifferencestringnumber (); return 0;}
Total Difference String