792. Number of Matching Subsequences Medium

@problem@discussion
#Hash Table#String#Trie#Sorting



1/**
2 * [792] Number of Matching Subsequences
3 *
4 * Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.
5 * A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
6 * 
7 * 	For example, "ace" is a subsequence of "abcde".
8 * 
9 *  
10 * Example 1:
11 * 
12 * Input: s = "abcde", words = ["a","bb","acd","ace"]
13 * Output: 3
14 * Explanation: There are three strings in words that are a subsequence of s: "a", "acd", "ace".
15 * 
16 * Example 2:
17 * 
18 * Input: s = "dsahjpjauf", words = ["ahjpjau","ja","ahbwzgqnuk","tnmlanowax"]
19 * Output: 2
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= s.length <= 5 * 10^4
25 * 	1 <= words.length <= 5000
26 * 	1 <= words[i].length <= 50
27 * 	s and words[i] consist of only lowercase English letters.
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/number-of-matching-subsequences/
33// discuss: https://leetcode.com/problems/number-of-matching-subsequences/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn num_matching_subseq(s: String, words: Vec<String>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_792() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.