Created
January 28, 2019 21:42
-
-
Save roxsula/855e774de1a8b06d9554fbc624a08cc2 to your computer and use it in GitHub Desktop.
Alternating Characters HackerRank - Refreshing C knowledge - return an integer representing the minimum number of deletions to make the alternating string.
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 alternatingCharacters(char* s) { | |
int c = 0; | |
char* AB = "AB"; | |
char* BA = "BA"; | |
char *ptr1 = strstr(s, AB); | |
char *ptr2 = strstr(s, AB); | |
if (ptr1 != NULL || ptr2 != NULL) | |
{ | |
for (int i = 0; i < strlen(s) - 1; i++) { | |
if (s[i] == s[i + 1]) { | |
c += 1; | |
} | |
} | |
return c; | |
} | |
else | |
{ | |
return strlen(s) - 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment