20250324 finished.

This commit is contained in:
jackfiled 2025-03-24 14:14:46 +08:00
parent 9ec00796bb
commit 6ac5d2d67c
2 changed files with 36 additions and 0 deletions

View File

@ -556,3 +556,5 @@ mod p2680_maximum_or;
mod p2643_row_with_maximum_ones;
mod p2116_check_if_a_parentheses_string_can_be_valid;
mod p2255_count_prefixes_of_a_given_string;

View File

@ -0,0 +1,34 @@
/**
* [2255] Count Prefixes of a Given String
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn count_prefixes(words: Vec<String>, s: String) -> i32 {
words.iter().filter(|i| s.starts_with(i.as_str())).count() as i32
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_2255() {
assert_eq!(
3,
Solution::count_prefixes(
vec_string!("a", "b", "c", "ab", "bc", "abc"),
"abc".to_owned()
)
);
assert_eq!(
2,
Solution::count_prefixes(vec_string!("a", "a"), "aa".to_owned())
);
}
}