Last active
June 2, 2018 15:44
-
-
Save dbechrd/1d51f30ebb9872f4b0b17f312a5e0efa to your computer and use it in GitHub Desktop.
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