[LeetCode] Vowel-Consonant Score

3813. Vowel-Consonant Score

You are given a string s consisting of lowercase English letters, spaces, and digits.

Let v be the number of vowels in s and c be the number of consonants in s.

A vowel is one of the letters 'a', 'e', 'i', 'o', or 'u', while any other letter in the English alphabet is considered a consonant.

The score of the string s is defined as follows:

  • If c > 0, the score = floor(v / c) where floor denotes rounding down to the nearest integer.
  • Otherwise, the score = 0.

Return an integer denoting the score of the string.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
int vowelConsonantScore(string s) {
int v = 0, c = 0;
unordered_set<int> us{'a','e','i','o','u'};
for(auto& ch : s) {
if(!isalpha(ch)) continue;
if(us.count(ch)) v++;
else c++;
}
return c ? v / c : 0;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/vowel-consonant-score/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.