Problem
Count how many characters in text are vowels: a, e, i, o, u in either uppercase or lowercase.
Implement count_vowels(text).
Input
text: The text to inspect (ASCII characters).
Output
Return the number of vowels.
Einschränkungen
0 ≤ length ≤ 10,000
Beispiele
Eingabe:
text = "Hello World"
Erwartete Ausgabe:
expected = 3
Eingabe:
std::string text = "Hello World";
Erwartete Ausgabe:
long long expected = 3;
Eingabe:
string text = "Hello World";
Erwartete Ausgabe:
long expected = 3;
Erläuterung
e, o and o are vowels: 3.
Eingabe:
text = "AEIOU and y"
Erwartete Ausgabe:
expected = 6
Eingabe:
std::string text = "AEIOU and y";
Erwartete Ausgabe:
long long expected = 6;
Eingabe:
string text = "AEIOU and y";
Erwartete Ausgabe:
long expected = 6;
Erläuterung
A, E, I, O, U, a are vowels; y is not counted: 6.
So gehst du vor
Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.
Hinweis 1
Scan the text once and test each character against the vowel set.
Hinweis 2
Treat uppercase and lowercase vowels as the same kind of letter.
Hinweis 3
An empty string should simply return zero.
Erwartete Komplexität
O(n) time, O(1) extra space
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.