Skip to main content
Back to problems
#3813
Easy Algorithms

Vowel consonant score

String Simulation
53.9% acceptance
Mar 16, 2026
48
4
You are given a string s consisting of lowercase English letters, spaces, and digits. v = number of vowels, c = number of consonants. Score = floor(v / c) if c > 0, else 0.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn vowel_consonant_score(s: String) -> i32 {
    let mut v = 0i32;
    let mut c = 0i32;
    for ch in s.chars() {
      match ch {
        'a' | 'e' | 'i' | 'o' | 'u' => v += 1,
        'b'..='z' => c += 1,
        _ => {}
      }
    }
    if c > 0 { v / c } else { 0 }
  }
}