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