class Solution {
public:
bool isAnagram(string s, string t) {
char data1[26] = {0};
char data2[26] = {0};
if (s.length() != t.length())
return false;
for (int i = 0; i < s.length(); i++)
{
data1[s[i] - 'a']++;
}
for (int i = 0; i < t.length(); i++)
{
data2[t[i] - 'a']++;
}
for (int i = 0; i < 26; i++)
{
if (data1[i] != data2[i])
{
return false;
}
}
return true;
}
};
public:
bool isAnagram(string s, string t) {
char data1[26] = {0};
char data2[26] = {0};
if (s.length() != t.length())
return false;
for (int i = 0; i < s.length(); i++)
{
data1[s[i] - 'a']++;
}
for (int i = 0; i < t.length(); i++)
{
data2[t[i] - 'a']++;
}
for (int i = 0; i < 26; i++)
{
if (data1[i] != data2[i])
{
return false;
}
}
return true;
}
};
评论
发表评论