class Solution(object):
    def findAnagrams(self, s, p):
        """
        :type s: str
        :type p: str
        :rtype: List[int]
        """
        reslist=[];sdic={};pdic={}
        ls=len(s)
        lp=len(p)
        
        for i in s[:lp]:
            sdic[i]=sdic.get(i,0)+1
        for i in p[:lp]:
            pdic[i]=pdic.get(i,0)+1
        i=0
        while i<ls-lp:
            if sdic==pdic:reslist.append(i)
            sdic[s[i]]-=1
            if sdic[s[i]]==0:
                del sdic[s[i]]
            sdic[s[i+lp]]=sdic.get(s[i+lp],0)+1
            i+=1
        if sdic==pdic:
            reslist.append(i)
        
        return reslist

【leetcode❤python】 438. Find All Anagrams in a String的更多相关文章

  1. 【leetcode❤python】387. First Unique Character in a String

    #-*- coding: UTF-8 -*- class Solution(object):    def firstUniqChar(self, s):        s=s.lower()     ...

  2. 【leetcode】438. Find All Anagrams in a String

    problem 438. Find All Anagrams in a String solution1: class Solution { public: vector<int> fin ...

  3. 【LeetCode】438. Find All Anagrams in a String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 滑动窗口 双指针 日期 题目地址:https://l ...

  4. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  5. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  6. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  7. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  8. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

  9. 【leetcode❤python】 168. Excel Sheet Column Title

    class Solution(object):    def convertToTitle(self, n):        """        :type n: in ...

随机推荐

  1. SQL2005中的事务与锁定(二)- 转载

    ------------------------------------------------------------------------ -- Author : HappyFlyStone  ...

  2. 设置Sql Agent运行Job时的执行账户

    相信使用过Sql Server的人都应该知道,使用Sql Agent可以建立一些自动化Job来帮我们周期性地执行一些任务,其中执行SSIS包就是其中一个任务.而在SSIS包中有时候会去做读取文件等一些 ...

  3. 项目中的一个JQuery ajax实现案例

    /**  * brief 这些代码用于在线制图中 attention author <list of authors> <date> begin modify by  * nu ...

  4. 统计SQL语句耗时百分比

    -- sql语句耗时百分比 declare @tmptb table(id int,name varchar(50),total_worker_time bigint,rate varchar(50) ...

  5. ubuntu下搭建JAVA开发环境【转】

    转自:http://jingyan.baidu.com/article/86fae346b696633c49121a30.html JAVA开发环境是一种跨平台的程序设计语言,可以在windows.L ...

  6. Android:Intent传递数据的几种类型和源码实现

    public class Intent implements Parcelable, Cloneable {   //... private String mAction; private Uri m ...

  7. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.2.jqGrid Model-View-Controller 分离

    1 基本 分离代码 和 描述 ,在ASP.NET MVC 应用程序中是非常重要的.因此,jqGrid 的 mvc 模式使用一个共同的网格安装设置,包括 Model ,Controller 和 View ...

  8. 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.5.Accordion控件

    accordion是另一个UI控件,能允许你将一组content加入相互分隔的.能够被浏览者的交互打开或关闭的panels中.因此,它大多数的content在初始化的时候是隐藏的,很像tabs控件.每 ...

  9. JavaEE基础(二十一)/IO流

    1.IO流(字符流FileReader) 1.字符流是什么 字符流是可以直接读写字符的IO流 字符流读取字符, 就要先读取到字节数据, 然后转为字符. 如果要写出字符, 需要把字符转为字节再写出. 2 ...

  10. POJ 3237:Tree(树链剖分)

    http://poj.org/problem?id=3237 题意:树链剖分.操作有三种:改变一条边的边权,将 a 到 b 的每条边的边权都翻转(即 w[i] = -w[i]),询问 a 到 b 的最 ...