Given two string and return a true value if an anagram otherwise return false
This problem is very simple and it is used to simple and pretty approach.
Step 1: from the beginning, we have sorted the couple string
Step 2: After that, we are returned both strings are equal
Code
class Solution {
public:
bool isAnagram(string s, string t) {
sort(s.begin(), s.end());
sort(t.begin(), t.end());
return s==t;
}
};
0 Comments