题解 | #牛牛的串联子串游戏#

牛牛的串联子串游戏

https://www.nowcoder.com/practice/c1984371372b43f3b10bf6d0231520bb

class Solution:
    def findSubstring(self , s: str, words: List[str]) -> List[int]:
        # write code here
        ans, wordLen = [], len(words[0])

        cnt = dict()
        for i, word in enumerate(words):
            cnt[word] = i

        strs = []
        for index in range(0, len(s), wordLen):
            if s[index:index+wordLen] in words:
                strs.append(cnt[s[index:index+wordLen]])
            else:
                strs.append(-1)

        seen = []
        for i, ss in enumerate(strs):

            if ss == -1:
                if len(seen) == len(words):
                    ans.append(i - len(words))
                seen.clear()
                continue

            if ss not in seen:
                seen.append(ss)
            else:
                if len(seen) == len(words):
                    ans.append(i - len(words))
                while seen and ss in seen:
                    seen.pop(0)


        if seen and len(seen) == len(words):
            ans.append(len(words) - len(seen))

        for i, a in enumerate(ans):
            ans[i] = a * wordLen

        return ans

滑动窗口

全部评论

相关推荐

05-12 11:09
已编辑
门头沟学院 后端
已注销:没必要放这么多专业技能的描述。这些应该是默认已会的,写这么多行感觉在凑内容。项目这块感觉再包装包装吧,换个名字,虽然大家的项目基本都是网上套壳的,但是你这也太明显了。放一个业务项目,再放一个技术项目。技术项目,例如中间件的一些扩展和尝试。
简历中的项目经历要怎么写
点赞 评论 收藏
分享
那一天的Java_J...:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
昨天 12:20
门头沟学院 运营
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务