很简单,但是细节上容易犯错,建议再写一遍。
#include<iostream>
#include<string>
using namespace std;
class Soluation {
public:
bool isAnagram(string s, string t) {
int hash[26] = { 0 };
if (s.size() != t.size()) return false;
for (int i = 0; i < s.size(); i++) {
hash[s[i] - 'a']++;
hash[t[i] - 'a']--;
}
for (int j = 0; j < 26; j++)
{
if (hash[j] != 0) return false;
}
return true;
}
};