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.
Input: s = "foobar", letter = "o" Output: 33 Explanation: The percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we return 33.
Input: s = "jjjj", letter = "k" Output: 0 Explanation: The percentage of characters in s that equal the letter 'k' is 0%, so we return 0.
1 <= s.length <= 100
s
consists of lowercase English letters.letter
is a lowercase English letter.
impl Solution {
pub fn percentage_letter(s: String, letter: char) -> i32 {
(s.chars().filter(|&c| c == letter).count() * 100 / s.len()) as i32
}
}