## 您将获得一个字符串s,以及一个长度相同单词的列表。
## 找到s中substring(s)的所有起始索引,它们只包含所有单词,
## eg:s: "barfoothefoobarman" words: ["foo", "bar"]
## return [0,9].

def find_sub(s,words):
    m,n,o=len(s),len(words[0]),len(words)
    for i in words:
        assert len(i)==n,'words length is not equal'
    def ch(l,n):
        return set([l[i:i+3] for i in range(0,len(l),n)])
    q=set(words)
    return [i for i in range(m-n*o+1) if ch(s[i:i+n*o],n)==q]

s,words="barfoothefoobarman",["foo", "bar"]
print(find_sub(s,words))

leetcode python 030 Substring with Concatenation of All Words的更多相关文章

  1. [Leetcode][Python]30: Substring with Concatenation of All Words

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 30: Substring with Concatenation of All ...

  2. leetcode面试准备: Substring with Concatenation of All Words

    leetcode面试准备: Substring with Concatenation of All Words 1 题目 You are given a string, s, and a list o ...

  3. LeetCode 030 Substring with Concatenation of All Words

    题目要求:Substring with Concatenation of All Words You are given a string, S, and a list of words, L, th ...

  4. LeetCode HashTable 30 Substring with Concatenation of All Words

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

  5. Java for LeetCode 030 Substring with Concatenation of All Words【HARD】

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

  6. leetcode@ [30/76] Substring with Concatenation of All Words & Minimum Window Substring (Hashtable, Two Pointers)

    https://leetcode.com/problems/substring-with-concatenation-of-all-words/ You are given a string, s, ...

  7. 【一天一道LeetCode】#30. Substring with Concatenation of All Words

    注:这道题之前跳过了,现在补回来 一天一道LeetCode系列 (一)题目 You are given a string, s, and a list of words, words, that ar ...

  8. [LeetCode][Python]Longest Substring Without Repeating Characters

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  9. 【LeetCode】30. Substring with Concatenation of All Words

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

随机推荐

  1. oracle中实现某个用户truncate 其它用户下的表

    oracle文档中对truncate权限的要求是需要某表在当前登录的用户下,或者当前登录的用户有drop any table的权限. 但是如果不满足第一个条件的情况下,要让某用户满足第二个条件就导致权 ...

  2. JavaScript--浅谈!=、!==、==和===的区别

    == 和 != 比较若类型不同,先偿试转换类型,再作值比较,最后返回值比较结果 === 和 !== 只有在相同类型下,才会比较其值 <!DOCTYPE html> <html> ...

  3. c# 文件与流

    1.创建和删除目录 在c#中涉及到输入.输出(i/o)相关操作的API都被放在System.IO命名空间下,或者子命令System.IO.IsolatedStoorage中.对目录进行操作可以使用Di ...

  4. springboot使用hibernate validator校验

    一.参数校验 在开发中经常需要写一些字段校验的代码,比如字段非空,字段长度限制,邮箱格式验证等等,写这些与业务逻辑关系不大的代码个人感觉有两个麻烦: 验证代码繁琐,重复劳动 方法内代码显得冗长 每次要 ...

  5. Windows下用python来获取微信撤回消息

    转自:https://blog.csdn.net/sunzhibin1/article/details/83348304 娱乐(windows系统) 安装itchat itchat是一个开源的pyth ...

  6. 解决使用eclipse创建maven web项目时报Could not resolve archetype的问题

    前两天重装了系统,今天想写一个项目的时候出现了点问题. 在使用eclipse创建maven web项目时,点Finish后报了Could not resolve archetype的问题. Could ...

  7. 剑指offer(4)重建二叉树

    题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...

  8. C# 可指定并行度任务调度器

    可指定并行度的任务调度器 https://social.msdn.microsoft.com/Forums/zh-CN/b02ba3b4-539b-46b7-af6b-a5ca3a61a309/tas ...

  9. java程序员面试交流项目经验

    粘贴自:https://blog.csdn.net/wangyuxuan_java/article/details/8778211 1:请你介绍一下你自己 这是面试官常问的问题.一般人回答这个问题过于 ...

  10. [JSONObject/JSONArray] - 定制的JSON格式返回

    当前开发的程序中.因为抛弃了jsp的渲染,改为thymeleaf,并在比较厉害的前端进行数据json的渲染无误后,得出此json数据返回. 以往的Map<String,Object>返回j ...