BudiBadu Logo

Vowel Counter

String Easy 3 views
Like30

The objective is to determine the frequency of vowels (a, e, i, o, u) distributed throughout the character sequence of string s. This task requires isolating each character to verify its membership within the standard set of vowel graphemes.

The final output must represent the total count of identified vowels while ensuring the verification remains case-insensitive. This count provides a character-level analysis of the linguistic composition within the provided text sample.

Example 1:

Input: s = "apple"
Output: 2

Example 2:

Input: s = "sky"
Output: 0

Example 3:

Input: s = "education"
Output: 5

Algorithm Flow

Recommendation Algorithm Flow for Vowel Counter - Budibadu
Recommendation Algorithm Flow for Vowel Counter - Budibadu

Best Answers

java
class Solution {
    public int count_vowels(String s) {
        int count = 0;
        String vowels = "aeiouAEIOU";
        for (char c : s.toCharArray()) {
            if (vowels.indexOf(c) != -1) count++;
        }
        return count;
    }
}