Easy C solution 3ms


  • 0
    bool isAnagram(char* s, char* t) {
        unsigned char* us = (unsigned char*)s;
        unsigned char* ut = (unsigned char*)t;
        int charCount[256] = {0};
        int index = 0;
        char tmp;
        while((tmp=ut[index])!=0){
            charCount[tmp] += 1;
            index ++;
        }
        index = 0;
        while((tmp=us[index])!=0){
            charCount[tmp] -= 1;
            index ++;
        }
        for(int i=0; i<255; i++){
            if(charCount[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.