## 您将获得一个字符串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. 函数作用域之闭包与this!

    函数基础友情链接:http://speakingjs.com/es5/ch01.html#_functions 作用域链图解   var x = 1; function foo(){     var ...

  2. [ Python ] OpenGL

    pyOpenGL Installation Package Version------------------- -------numpy 1.14.2 PyOpenGL 3.1.0 PyOpenGL ...

  3. OpenStack-Neutron-安全组

    neutron中目前安全组的实现是使用iptables来实现的 创建安全组 创建安全组的时候默认有两条“出”规则(ipv4和ipv6) “default”安全组不仅有“出”规则,还有“入”规则.默认有 ...

  4. mybatis源码解析12---ResultSetHandler解析

    说完了StatementHandler和ParameterHandler,接下来就需要对查询的结果进行处理了,而对于sql结果的处理是由ResultSetHandler处理的,ResultHandle ...

  5. powerdesigner相关记录

    背景 项目逐步开始规范化,表设计直接用designer来,然后生成语句,到oracle数据库,把相关的操作等记录一下, designer版本:15.1 oracle版本:11.2,64位 oracle ...

  6. java线程学习之线程创建

    线程是程序控制的一个内部数据流.线程的状态转化如下 或者 在java中创建线程有两种方式: 1.实现runnable接口(这个比较好,推荐这个.原因是:用的时候比较灵活,相比较继承Thread类,用接 ...

  7. P3628 [APIO2010]特别行动队(斜率优化dp)

    P3628 [APIO2010]特别行动队 设$s[i]$为战斗力前缀和 显然我们可以列出方程 $f[i]=f[j]+a*(s[i]-s[j])^{2}+b*(s[i]-s[j])+c$ $f[i]= ...

  8. Python2.x与3.x对比

    1.默认支持中文 2.不再兼容2.x 3.核心语法调整 4.新特性默认只支持3.x

  9. easyUI使用dailog实现弹出框带表单功能

    本文为博主原创,未经允许不得转载: 示例如下: 需要注意的地方在id为win的div中需要有:closed="true"这个属性,这个属性为控制dailogn对话框显示与隐藏的属性 ...

  10. ssm 整合(方案二 maven)

    通过maven来整合ssm方便很多,至少不用去找jar包 具体架构如下: 1.配置pom.xml <project xmlns="http://maven.apache.org/POM ...