【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 ...
随机推荐
- DMA-330(二)
DMA内部的block diagram: DMAC包含一个instruction processing block,来process program code,control DMA transfer ...
- Html基础知识讲解
Html基础知识讲解 <title>淄博汉企</title> </head> <body bgcolor="#66FFCC" topmar ...
- z/os上的tar和gzip
在*nix平台上玩过的人都知道,tar和gzip基本上是每天都要使用的,而且非常之好用.而Mainframer则比较痛苦,没有这么好用的东西,尤其是当需要通过网络传大批量的文件的时候很不方便. 不过总 ...
- sql server中index的REBUILD和REORGANIZE
参考文献: http://technet.microsoft.com/en-us/library/ms188388.aspx 正文 本文主要讲解如何使用alter index来rebuild和reor ...
- StringTokenizer类
StringTokenizer是一个用来分隔String字符串的应用类. 1.构造函数 public StringTokenizer(String str) //构造一个用来解析str的String ...
- Windows系统文件受损的修复技巧
Windows2000/XP系统文件受损的修复技巧 意外重启.安装了不兼容的软件.恶意程序侵扰.误删文件……有太多种可能性会使我们的系统文件受损,而系统文件受损后最直接的表现就是系统不稳定.经常出现错 ...
- 想学习一下CSS函数
好像原来都是用前后端代码实现的功能,如今CSS3已经吸纳为标准,使用简单的选择器就可以实现了.
- Android侧滑
人人客户端有一个特效还是挺吸引人的,在主界面手指向右滑动,就可以将菜单展示出来,而主界面会被隐藏大部分,但是仍有左侧的一小部分同菜单一起展示. 据说人人客户端的这个特效是从facebook客户端模仿来 ...
- http-使用get和post方式提交数据
注意点: 1.Get和post这两种提交方式有何不同? 很明显post方式提交多了content-length和content-type这两项,所以post提交是要为这两项设置setRequestPr ...
- 使用BusyBox制作根文件系统【转】
本文转载自:http://www.cnblogs.com/lidabo/p/5300180.html 1.BusyBox简介 BusyBox 是很多标准 Linux 工具的一个单个可执行实现.Busy ...