美文网首页
792. 匹配子序列的单词数(jie)

792. 匹配子序列的单词数(jie)

作者: cptn3m0 | 来源:发表于2019-03-23 13:51 被阅读0次
class Solution(object):
    def numMatchingSubseq(self, S: str, words: List[str]) -> int:
        res = 0
        d = {}
        for i in range(len(words)):
            if words[i][0] in d:
                d[words[i][0]].append([i, 0])
            else:
                d[words[i][0]] = [[i, 0]]
        for s in S:
            if s not in d:
                continue
            cur = d[s]
            d[s] = []
            for [i, j] in cur:
                if j == len(words[i]) - 1:
                    res += 1
                else:
                    if words[i][j + 1] in d:
                        d[words[i][j + 1]].append([i, j + 1])
                    else:
                        d[words[i][j + 1]] = [[i, j + 1]]
        return res

相关文章

  • 792. 匹配子序列的单词数(jie)

  • 792. 匹配子序列的单词数

    暴力算法果断超时

  • 792. 匹配子序列的单词数(Python)

    难度:★★★☆☆类型:字符串方法:桶 力扣链接请移步本题传送门[https://leetcode-cn.com/p...

  • 生物

    XY型性别决定的生物,雌配子都是含X染色体的配子,雄配子中含有X染色体的配子和含有Y染色体的配子之比接近1:1

  • kmp_algorithm

    tips:kmp算法分两个步骤:1)计算子串的next数组2)匹配子串conclusion:其实求next数组和匹...

  • 算法题--找到最短匹配子序列

    0. 链接 题目链接 1. 题目 Given a string S and a string T, find th...

  • JIE

    在看到这篇文章的题目时,我相信很多人会有疑问,为什么用这么一个拼音来做题目呢? 我当然不会平白无故的拿...

  • jie

    看到这个字,你会怎么理解? 本来想写的是“结”,纠结的结。 刚看了一个视频,居然说婚姻是一个人的事……只需要搞明白...

  • Jie

  • ABAP和Java单例模式的攻防

    ABAP 通过序列化/反序列化攻击单例模式: 绕过了单例的限制,构造了第二个实例。 Java 除了用序列化/反序列...

网友评论

      本文标题:792. 匹配子序列的单词数(jie)

      本文链接:https://www.haomeiwen.com/subject/hjhsvqtx.html