To count vowels in a string, I would iterate through each character and check if it belongs to the set of vowels: a, e, i, o, u. I can implement this efficiently in O(n) time complexity, where n is the length of the string.
Here’s a simple approach in C#:
- Initialize a counter to zero.
- Loop through each character in the string.
- If the character is a vowel, increment the counter.
This method is straightforward and handles any string length effectively.