Created
January 28, 2019 16:14
-
-
Save roxsula/eb2d1bf8cbae7b17a4b00222f78adcc6 to your computer and use it in GitHub Desktop.
HackerRank Strings: Making Anagrams - I'm trying to refresh my C knowledge. This program returns an integer representing the minimum total characters that must be deleted to make the strings anagrams.
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
int Count(char* s, char c) { | |
// Count variable | |
int res = 0; | |
for (int i = 0; i < strlen(s); i++) | |
// checking character in string | |
if (s[i] == c) | |
res++; | |
return res; | |
} | |
// Complete the makeAnagram function below. | |
int makeAnagram(char* a, char* b) { | |
int count = 0; | |
int ai = 0; | |
int bi = 0; | |
for (int i = (int)'a'; i <= (int)'z'; i++) | |
{ | |
ai = Count(a, (char)i); | |
bi = Count(b, (char)i); | |
count += abs(ai - bi); | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment