## 您将获得一个字符串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. Python记录14:面向对象编程 类和对象

    '''现在主流的编程思想有两种,一种是面向对象,一种是面向过程面向过程编程 核心是过程二字,过程指的是解决问题的步骤,即先干什么.再干什么.最后干什么... 基于该思想编写程序就好比再设计一条流水线, ...

  2. CentOS 7 使用OwnCloud建立私有云储存网盘

    使用OwnCloud建立属于自己私有的云存储网盘 OwnCloud概述: OwnCloud 一款文件主机服务软件,就是我们平时使用的云存储,不过这是在自己主机的服务器上建立属于自己的私有云,OwnCl ...

  3. FractionallySizedBox

    import 'package:flutter/material.dart'; void main() { runApp(MaterialApp(home: new MyApp())); } clas ...

  4. PHP 订单延时处理:延迟队列(未鉴定)

    PHP 订单延时处理:延迟队列: https://github.com/chenlinzhong/php-delayqueue

  5. Bitmap的秘密

    作者: 周海鹏  来源: infoQ  发布时间: 2015-02-13 11:26  阅读: 4999 次  推荐: 10   原文链接   [收藏] 之前已经参加过几次QCon峰会,不过今年QCo ...

  6. 解决ajax异步请求数据后swiper不能循环轮播(loop失效)问题、滑动后不能轮播的问题。

    问题描述: 1.我使用axios异步请求后台的图片进行渲染后不能实现循环轮播,也就是loop失效,但是静态写死的情况下不会出现这种问题. 2. 分析: swiper的机制是:初始化的时候将swiper ...

  7. echarts2.0tooltip边框限制导致tooltip显示不全解决办法

    1.显示常数位置x和y; 2.根据鼠标移动显示:tooltip : { trigger: 'axis', position:function(p){ //其中p为当前鼠标的位置 return [p[0 ...

  8. Oracle11g导出为Oracle10g版本数据,解决10g不兼容11g文件

    EXPDP USERID='JCSJ/JCSJ@FZBD' schemas=JCSJ directory=bac_file dumpfile=JCSJ.dmp logfile=JCSJ.log ver ...

  9. AndroBench手机性能测试【转】

    本文转载自:https://www.cnblogs.com/jiangzhishan/archive/2018/07/16/9316279.html AndroBench是一个基准测试应用程序,可以衡 ...

  10. 马上AI全球挑战者大赛-违约用户风险预测

    方案概述 近年来,互联网金融已经是当今社会上的一个金融发展趋势.在金融领域,无论是投资理财还是借贷放款,风险控制永远是业务的核心基础.对于消费金融来说,其主要服务对象的特点是:额度小.人群大.周期短, ...