Given two strings s and t, write a function to determine if t is an anagram of s.
class Solution {
public:
bool isAnagram(string s, string t) {
int lens = s.length();
int lent = t.length();
if(lens != lent)
{
return false;
}
int a[30],b[30];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0;i<lens;i++){
int xs = s[i] - 'a';
int xt = t[i] - 'a';
a[xs]++;
b[xt]++;
}
for(int i=0; i<26 ; i++){
if(a[i]!=b[i])
return false;
}
return true;
}
};
1万+




被折叠的 条评论
为什么被折叠?



