【leetcode❤python】 438. Find All Anagrams in a String
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的更多相关文章
- 【leetcode❤python】387. First Unique Character in a String
#-*- coding: UTF-8 -*- class Solution(object): def firstUniqChar(self, s): s=s.lower() ...
- 【leetcode】438. Find All Anagrams in a String
problem 438. Find All Anagrams in a String solution1: class Solution { public: vector<int> fin ...
- 【LeetCode】438. Find All Anagrams in a String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 滑动窗口 双指针 日期 题目地址:https://l ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
- 【leetcode❤python】 165. Compare Version Numbers
#-*- coding: UTF-8 -*-class Solution(object): def compareVersion(self, version1, version2): ...
- 【leetcode❤python】 168. Excel Sheet Column Title
class Solution(object): def convertToTitle(self, n): """ :type n: in ...
随机推荐
- 夺命雷公狗---微信开发55----微信js-sdk接口开发(2)接口功能介绍之签名算法
我们JS-SDK里面其实有不少的接口 startRecord---录音 stopRecord---停止录音 playVoice---播放 pauseVoice---暂停播放 uploadImage-- ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON AffineTransImage
zw版[转发·台湾nvp系列Delphi例程]HALCON AffineTransImage unit Unit1;interfaceuses Windows, Messages, SysUtils, ...
- ASP.NET MVC的TempData(转载)
本文章基于ASP.NET MVC Preview5. ASP.NET MVC的TempData用于传输一些临时的数据,例如在各个控制器Action间传递临时的数据或者给View传递一些临时的数据,相信 ...
- C#抽象类及其方法的学习【转】
转至 http://www.cnblogs.com/flyinthesky/archive/2008/06/18/1224774.html 在C#中使用关键字 abstract 来定义抽象类和抽象方法 ...
- USB 设备类协议入门【转】
本文转载自:http://www.cnblogs.com/xidongs/archive/2011/09/26/2191616.html 一.应用场合 USB HID类是比较大的一个类,HID类设备属 ...
- Linux Kernel中断子系统来龙去脉浅析【转】
转自:http://blog.csdn.net/u011461299/article/details/9772215 版权声明:本文为博主原创文章,未经博主允许不得转载. 一般来说,在一个device ...
- 这个Glance的界面该怎么看出问题,为什么状态是SOCKT?
这个glance的状态图有问题吗?
- win10启动文件夹:
win10启动文件夹: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
- struts2的两个核心配置文件
struts2的两个核心配置文件,即:struts.default.xml和struts.properties A,位置:都在struts2-core-version.jar文件中 B,作用,stru ...
- 《图解TCP/IP》
MAC寻址:地址转发表:IP寻址:路由控制表. 网卡(网络接口卡),NIC. 循环复用DNS技术. 代理服务器是一种应用网关.防火墙. LLC是Logical Link Control的缩写,意为:逻 ...