C solution (3ms)


  • 0
    #define CHAR_SET_SIZE ('z' - 'a' + 1)
    
    bool isAnagram(char* s, char* t) {
        if (strlen(s) != strlen(t)) { return false; }
        int table[CHAR_SET_SIZE];
        memset(table, 0, sizeof(table));
        while (*s) { table[*(s++) - 'a']++; }
        while (*t) { table[*(t++) - 'a']--; }
        for (int i = 0; i < CHAR_SET_SIZE; i++) {
            if (table[i] != 0) {
                return false;
            }
        }
        return true;
    }
    

Log in to reply
 

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