假期动手写的第一题!
解法:采用数字数组计数对消的方法。在题解区叫这种方法为Hash表法,其实仔细想想确实是用一个数组实现的哈希表。
class Solution {
public:
bool isAnagram(string s, string t) {
if(s.length()!=t.length()) return false;
vector<int> count(26);
for(int i=0; i<s.length(); ++i) {
count[s[i]-'a']++;
count[t[i]-'a']--;
}
for(int i=0; i<26; ++i) {
if (count[i]!=0) return false;
}
return true;
}
};