Skip to content

Instantly share code, notes, and snippets.

@dbechrd
Last active June 2, 2018 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbechrd/1d51f30ebb9872f4b0b17f312a5e0efa to your computer and use it in GitHub Desktop.
Save dbechrd/1d51f30ebb9872f4b0b17f312a5e0efa to your computer and use it in GitHub Desktop.
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