반응형
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, u as vowels for this Kata (but not y).
The input string will only consist of lower case letters and/or spaces.
Solution:
int getCount(String inputStr){
List<String> arr = [];
for (String s in inputStr.toLowerCase().split('')) {
if (["a","e","i","o","u"].contains(s)) {
arr.add(s);
}
}
return arr.length;
}
import "dart:core";
int getCount(String str) => new RegExp('[aeiou]').allMatches(str).length;
int getCount(String inputStr){
return inputStr.split('').fold(0, (a, b) => a += 'aeiou'.contains(b) ? 1 : 0 );
}
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1209. Grasshopper - Combine strings (0) | 2022.12.09 |
---|---|
1208. A Strange Trip to the Market (0) | 2022.12.08 |
1206. Sum of positive (0) | 2022.12.06 |
1205. Sum of Cubes (0) | 2022.12.05 |
1204. Odd or Even? (0) | 2022.12.04 |