leetcode——792. 匹配子序列的单词数

执行用时 :1780 ms, 在所有 python3 提交中击败了12.50%的用户
内存消耗 :15 MB, 在所有 python3 提交中击败了32.00%的用户
class Solution:
    def numMatchingSubseq(self, S: str, words: List[str]) -> int:
        m=0
        for i in range(len(words)):
            j=0
            t=S
            while j<len(words[i]):
                if words[i][j] in t:
                    d=t.index(words[i][j])
                    t=t[d+1:]
                    j+=1
                else:
                    break
            if j==len(words[i]):
                m+=1
        return m

耗时太多,如何优化???

有人说用双指针,我还没试。

                                                               ——2019.10.16

 

posted @ 2019-10-16 17:55  欣姐姐  阅读(288)  评论(0编辑  收藏  举报