diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 0f88d31..212ea11 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -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; diff --git a/src/problem/p2255_count_prefixes_of_a_given_string.rs b/src/problem/p2255_count_prefixes_of_a_given_string.rs new file mode 100644 index 0000000..c8b0a02 --- /dev/null +++ b/src/problem/p2255_count_prefixes_of_a_given_string.rs @@ -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, 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()) + ); + } +}