Easy to understand c solution


  • 1
    D
    bool isAnagram(char* s, char* t) {
    int M[26] = {0};
    while(*(s)!='\0') M[*(s++)-97]++;
    while(*(t)!='\0'){
    	if(M[*(t)-97] > 0) M[*(t)-97]--;
    	else{
        	M[*(t)-97] ++;
        }
        t++;
    }
    for(int i=0;i<26;i++){
    	if (M[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.