Given two strings s and t, write a function to determine if t is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
You may assume the string contains only lowercase alphabets.
class Solution {
public:
bool isAnagram(string s, string t)
{
int ht1[256] = {0};
for(int i = 0; i < s.size(); ++i)
{
ht1[s[i]]++;
}
int ht2[256] = {0};
for(int i = 0; i < t.size(); ++i)
{
ht2[t[i]]++;
}
for(int i = 0; i < 256; ++i)
{
if(ht1[i] != ht2[i])
{
return false;
}
}
return true;
}
};