mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
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>
This commit is contained in:
parent
1d07d142d0
commit
bf94aff668
@ -106,6 +106,7 @@
|
||||
| 1769 | [Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box/) | [C](./src/1769.c) | Medium |
|
||||
| 1524 | [Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/) | [C](./src/1524.c) | Medium |
|
||||
| 1653 | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/) | [C](./src/1653.c) | Medium |
|
||||
| 1704 | [Determine if String Halves Are Alike](Determine if String Halves Are Alike) | [C](./src/1704.c) | Easy |
|
||||
| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/) | [C](./src/1752.c) | Easy |
|
||||
| 2024 | [Maximize the Confusion of an Exam](https://leetcode.com/problems/maximize-the-confusion-of-an-exam/) | [C](./src/2024.c) | Medium |
|
||||
| 2130 | [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/) | [C](./src/2130.c) | Medium |
|
||||
|
38
leetcode/src/1704.c
Normal file
38
leetcode/src/1704.c
Normal file
@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user