Total Difference String

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.