LeetCode 242 Valid Anagram

LeetCode 242 Valid Anagram

由于都是小写字母,可以建立一个长度为26的数组来记录每个字母出现的次数。C语言实现如下:

bool isAnagram(char* s, char* t) {
    if(strlen(s)!=strlen(t))
        return 0;
    int count[26] = {0};
    char c;
    while ((c=*s++)!='')
        count[c-'a']++;
    while ((c=*t++)!='')
        count[c-'a']--;
    for (int i=0; i<26 ;++i)
        if (count[i]!=0)
            return 0;
    return 1;
}
原文地址:https://www.cnblogs.com/walker-lee/p/4963960.html