20250331 finished.
This commit is contained in:
parent
d9b5ef618f
commit
9625c44d8b
|
@ -570,3 +570,5 @@ mod p2716_minimize_string_length;
|
||||||
mod p2360_longest_cycle_in_a_graph;
|
mod p2360_longest_cycle_in_a_graph;
|
||||||
|
|
||||||
mod p2109_adding_spaces_to_a_string;
|
mod p2109_adding_spaces_to_a_string;
|
||||||
|
|
||||||
|
mod p2278_percentage_of_letter_in_string;
|
||||||
|
|
25
src/problem/p2278_percentage_of_letter_in_string.rs
Normal file
25
src/problem/p2278_percentage_of_letter_in_string.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* [2278] Percentage of Letter in String
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn percentage_letter(s: String, letter: char) -> i32 {
|
||||||
|
(s.chars().filter(|c| *c == letter).count() * 100 / s.len()) as i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_2278() {
|
||||||
|
assert_eq!(33, Solution::percentage_letter("foobar".to_owned(), 'o'));
|
||||||
|
assert_eq!(0, Solution::percentage_letter("jjjj".to_owned(), 'k'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user