image.png
解法一:统计词频
class Solution {
public:
bool isAnagram(string s, string t) {
int word_s[26] = {0};
int word_t[26] = {0};
cout<
解法二:先排序,然后比较
class Solution {
public:
bool isAnagram(string s, string t) {
sort(s.begin(), s.end());
sort(t.begin(), t.end());
if(s == t){
return true;
}
else{
return false;
}
}
};