A simple 0ms c solution


  • 7
    W
    bool isAnagram(char* s, char* t) {
        int count[26] = {0};
        char c;
        while ((c=*s++)!='\0')
            count[c-'a']++;
        while ((c=*t++)!='\0')
            count[c-'a']--;
        for (int i=0; i<26 ;++i)
            if (count[i]!=0)
                return 0;
        return 1;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.