This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool is_anagram(const char *str1, const char *str2) | |
{ | |
int char_count[128] = { 0 }; | |
int len = strlen(str1); | |
for (int i = 0; i < len; i++) | |
{ | |
if (!str1[i] || !str2[i]) | |
return false; | |
char_count[str1[i]]++; | |
char_count[str2[i]]--; | |
} | |
for (int i = 0; i < sizeof(char_count); i++) | |
{ | |
if (char_count[i]) | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment