class Solution {
public:
bool halvesAreAlike(string s) {
string a = s.substr(0, s.length()/2);
string b = s.substr(s.length()/2, s.length());
int acnt = 0, bcnt = 0;
for(int i = 0; i < a.length(); i++) {
switch(tolower(a[i])) {
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' : acnt++; break;
default : break;
}
switch(tolower(b[i])) {
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' : bcnt++; break;
default : break;
}
}
return acnt == bcnt ? true : false;
}
};
'Problem Solving > 리트코드(leetcode)' 카테고리의 다른 글
[LeetCode/C++] 14. Longest Common Prefix (0) | 2022.01.23 |
---|---|
[LeetCode/C++] 844. Backspace String Compare (0) | 2022.01.20 |
Valid Perfect Square (0) | 2022.01.16 |
Sqrt(x) (0) | 2022.01.16 |
Self Dividing Numbers (0) | 2022.01.16 |