Skip to main content
Back to problems
#2278
Easy Algorithms

Percentage of letter in string

String
75.1% acceptance
Feb 25, 2026
560
64
Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn percentage_letter(s: String, letter: char) -> i32 {
    let count = s.chars().filter(|&c| c == letter).count();
    (count * 100 / s.len()) as i32
  }
}