2185. Counting Words With a Given Prefix Easy
1/**
2 * [2185] Counting Words With a Given Prefix
3 *
4 * You are given an array of strings words and a string pref.
5 * Return the number of strings in words that contain pref as a prefix.
6 * A prefix of a string s is any leading contiguous substring of s.
7 *
8 * Example 1:
9 *
10 * Input: words = ["pay","<u>at</u>tention","practice","<u>at</u>tend"], pref = "at"
11 * Output: 2
12 * Explanation: The 2 strings that contain "at" as a prefix are: "<u>at</u>tention" and "<u>at</u>tend".
13 *
14 * Example 2:
15 *
16 * Input: words = ["leetcode","win","loops","success"], pref = "code"
17 * Output: 0
18 * Explanation: There are no strings that contain "code" as a prefix.
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= words.length <= 100
24 * 1 <= words[i].length, pref.length <= 100
25 * words[i] and pref consist of lowercase English letters.
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/counting-words-with-a-given-prefix/
31// discuss: https://leetcode.com/problems/counting-words-with-a-given-prefix/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn prefix_count(words: Vec<String>, pref: String) -> i32 {
37 0
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_2185() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.