20250324 finished.
This commit is contained in:
parent
9ec00796bb
commit
6ac5d2d67c
|
@ -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;
|
||||
|
|
34
src/problem/p2255_count_prefixes_of_a_given_string.rs
Normal file
34
src/problem/p2255_count_prefixes_of_a_given_string.rs
Normal 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())
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user