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:
You may assume the string contains only lowercase alphabets.
判断组成两个字符串的字符是否相同。
统计一下每个字符出现的次数就行了。
class Solution {
public:
bool isAnagram(string s, string t) {
int cnt[26] = {0};
for(auto c : s) cnt[c - 'a']++;
for(auto c : t) cnt[c - 'a']--;
for(auto c : cnt) if(c) return false;
return s.size() != t.size() ? false : true;
}
};