TheAlgorithms-C/leetcode/src/1704.c
Alexander Pantyukhin bf94aff668
feat: add Determine if String Halves Are Alike LeetCode (#1168)
* add leetcode Determine if String Halves Are Alike

* fix variable  name

Co-authored-by: David Leal <halfpacho@gmail.com>
2022-12-16 15:43:25 -06:00

39 lines
714 B
C

bool isVowel(char chr){
switch(chr){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return true;
}
return false;
}
// Counting
// Runtime: O(n)
// Space: O(1)
bool halvesAreAlike(char * s){
int lenS = strlen(s);
int halfVowels = 0;
int currVowels = 0;
for (int i = 0; i < lenS; i++){
if (isVowel(s[i])){
currVowels++;
}
if (2 * (i + 1) == lenS){
halfVowels = currVowels;
}
}
return 2 * halfVowels == currVowels;
}