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) {
if (s.length() != t.length()){
return false;
}
vector<int> nums(26,0);
for (int i=0;i<s.length();i++){
nums[s[i]-'a']++;
}
for (int i=0;i<t.length();i++){
nums[t[i]-'a']--;
}
for (int i=0;i<26;i++){
if(nums[i] != 0){
return false;
}
}
return true;
}
};