首页 > 其他 > 详细

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

时间:2019-10-16 20:25:41      阅读:78      评论:0      收藏:0      [点我收藏+]
执行用时 :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

 

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

原文:https://www.cnblogs.com/taoyuxin/p/11687221.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!