## 您将获得一个字符串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. 蓝桥杯 基础训练 2n皇后

    数月前做的2N皇后基本看书敲代码的,然后发现当时的代码不对,正好做到算法提高的8皇后·改,顺便把以前的代码顺带改了下,题目如下: 问题描述 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋 ...

  2. lua常用方法收集

    1. xlua之将c#集合转换成table -- 将c#的list转换成table local function ConvertCSListToTable(list) local t = {}; , ...

  3. day05 Python中的set集合

    集合是无序的,不重复的数据集合,它里面的元素是可哈希的(不可变类型),但是集合本身是不可哈希(所以集合做不了字典的键)的.以下是集合最重要的两点: 1.去重,把一个列表变成集合,就自动去重了. 2.关 ...

  4. axios的封装

    function axios(options){ var promise = new Promise((resolve,reject)=>{ var xhr = null; if(window. ...

  5. Docker Swarm 高可用详解

    Docker Swarm 高可用详解 Manager管理节点宕机后其他管理节点仍然可以使用管理 intermal distributed state store:内部分布式状态存储同步共享到每个节点. ...

  6. 【题解】Luogu P2763 试题库问题

    原题传送门 这题很简单啊 从源点向k类题目分别连流量为所需数量的边 从每道题向汇点连一条流量为1的边(每题只能用1次) 从类型向对应的题目连一条流量为1的边 跑一遍最大流 如果最大流小于所需题目数量, ...

  7. JS设计模式(10)职责链模式(重要)

    什么是职责链模式? 重要性:4 星,在项目中能对 if-else 语句进行优化 定义:避免请求发送者与接收者耦合在一起,让多个对象都有可能接收请求,将这些对象连接成一条链,并且沿着这条链传递请求,直到 ...

  8. 剑指offer(45)扑克牌顺子

    题目描述 LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决 ...

  9. gitlab 迁移

    http://www.cnblogs.com/crysmile/p/9505527.html

  10. pip安装第三方库镜像源选择

    在pip安装时,有些库速度及其缓慢从而导致失败,可以通过更改镜像源的方式来安装. 我在安装的时候使用了清华的镜像源,格式如下: 想要安装什么库就在后面替换即可.