<jupyter_start><jupyter_text>说明：    给定字符串S和单词word的字典，找到作为S的子序列的单词数[i]。Example :    Input:         S = "abcde"    words = ["a", "bb", "acd", "ace"]    Output: 3    Explanation: There are three words in words that are a subsequence of S: "a", "acd", "ace".Note:    1、All words in words and S will only consists of lowercase letters.    2、The length of S will be in the range of [1, 50000].    3、The length of words will be in the range of [1, 5000].    4、The length of words[i] will be in the range of [1, 50].<jupyter_code>class Solution:
    def numMatchingSubseq(self, S: str, words) -> int:
        
        def get_freq(word):
            w_freq = {}
            for i, w in enumerate(word):
                if w not in w_freq:
                    w_freq[w] = [i]
                else:
                    w_freq[w].append(i)
            return w_freq
        
        s_freq = get_freq(S)
        print(s_freq)
        count = 0
        for w in words:
            pass
        return count
from collections import Counter

class Solution:
    def numMatchingSubseq(self, S: str, words) -> int:
        res = 0
        for w, c in Counter(words).items():
            i, match = 0, True
            # 一个单词一个单词找，找到之后，从下一位开始找
            for x in w:
                i = S.find(x, i) + 1
                if i == 0: # 没有找到就是-1，在+1就是0
                    match = False
                    break
            if match:
                res += c # words中的单词可能重复
        return res
S_ = 'abcde'
words_ = ["a", "bb", "acd", "ace"]
solution = Solution()
solution.numMatchingSubseq(S_, words_)
s = 'abced'
print(s.find('bd', 0))
a = -1
if not a:
    print(2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11084624553039332, 'fraction_numerical': 0.017878426698450536, 'mean_word_length': 1.734527687296417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '258904', 'license': 'Apache-2.0', 'n_tokens_mistral': 612, 'n_tokens_neox': 593, 'n_words': 181, 'path': 'Array/0922/792. Number of Matching Subsequences.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '1678'}