Checking if one string is a permutation of another in C++ -


i've been working on programming questions try refresh memory data structures , algorithms. problem checking see if 1 string permutation of another.

a lot of code solutions i've seen sorts each string, checks see if sorted strings equal each other. done doing this:

sort(strone.begin(), strone.end()); sort(strtwo.begin(), strtwo.end());  (int = 0; < strone.length(); i++)      {         if (strone[i] != strtwo[i])          {             return false;          }     } 

however, wondering if after sorting strings compare strings directly instead of using loop. example,

     if (strone == strtwo) {     return true;   } 

is there i'm missing in second option not work? feel missing basic concept because seems solutions have loop iterate string.

thanks in advance!

you can use str1.compare(str2) compare strings lexographically , return 0 if equal.

but, solution taking o(nlogn) complexity , can solved in linear time...