leetcode 242. Valid Anagram
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.
AC:
bool isAnagram(char* s, char* t) {
int a[26]={0};
int b[26]={0};
int len1=strlen(s);
int len2=strlen(t);
if(len1!=len2)
{
return false;
}
for(int i=0;i<len1;i++)
{
a[s[i]-'a']++;
}
for(int i=0;i<len2;i++)
{
b[t[i]-'a']++;
}
for(int i=0;i<26;i++)
{
if(a[i]!=b[i])
return false;
}
return true;
}
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?