当前位置:网站首页>Sword finger offer II 015 All modifiers in the string
Sword finger offer II 015 All modifiers in the string
2022-07-01 16:44:00 【Python ml】
The finger of the sword Offer II 015. All modifiers in the string
class Solution:
def findAnagrams(self, s: str, p: str) -> List[int]:
s_len,p_len=len(s),len(p)
if s_len<p_len:
return []
ans=[]
count=[0]*26
for i in range(p_len):
count[ord(p[i])-ord('a')]-=1
count[ord(s[i])-ord('a')]+=1
differ=0
for c in count:
if c!=0:
differ+=1
if differ==0:
ans.append(0)
for i in range(s_len-p_len):
left=ord(s[i])-ord('a') # Slide the letters discarded on the left side of the window
right=ord(s[i+p_len])-ord('a') # Slide the letters added to the right of the window
if count[left]==1: # Original letter left The quantity of is one more , After discarding differ--
differ-=1
elif count[left]==0:
differ+=1
count[left]-=1
if count[right]==0:
differ+=1
elif count[right]==-1:
differ-=1
count[right]+=1
if differ==0:
ans.append(i+1)
return ans
边栏推荐
- 【直播预约】数据库OBCP认证全面升级公开课
- [daily question] 1175 Prime permutation
- 怎么用MySQL语言进行行列装置?
- Chinese diosgenin market forecast and investment strategy report (2022 Edition)
- 数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
- [SQL statement] Why do you select two Shanghai and query different counts here? I want it to become a Shanghai, and count only displays a sum
- Red team Chapter 10: ColdFusion the difficult process of deserializing WAF to exp to get the target
- OJ questions related to complexity (leetcode, C language, complexity, vanishing numbers, rotating array)
- 数据库系统原理与应用教程(005)—— yum 离线安装 MySQL5.7(Linux 环境)
- Kali install Nessus
猜你喜欢
Template engine velocity Foundation
[nodemon] app crashed - waiting for file changes before starting... resolvent
Endeavouros mobile hard disk installation
Bugku's file contains
How to restore the system of Sony laptop
数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
C语言输入/输出流和文件操作
Motion capture system for apple picking robot
Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores
Is the programmer's career really short?
随机推荐
FPN网络详解
What is the digital transformation of manufacturing industry
P2893 [USACO08FEB] Making the Grade G(dp&优先队列)
【观察】数字化时代的咨询往何处走?软通咨询的思与行
剑指 Offer II 015. 字符串中的所有变位词
红队第8篇:盲猜包体对上传漏洞的艰难利用过程
Stegano in the world of attack and defense
I'm a senior test engineer who has been outsourced by Alibaba and now has an annual salary of 40w+. My two-year career changing experience is sad
UML旅游管理系统「建议收藏」
Leetcode 216 combined summation III -- backtracking method
Leetcode 77 combination -- backtracking method
Virtual serial port simulator and serial port debugging assistant tutorial "suggestions collection"
数据库系统原理与应用教程(003)—— MySQL 安装与配置:手工配置 MySQL(windows 环境)
Buuctf gold III
数据库系统原理与应用教程(002)—— MySQL 安装与配置:MySQL 软件的卸载(windows 环境)
EndeavourOS移动硬盘安装
Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
全面看待企业数字化转型的价值
The supply of chips has turned to excess, and the daily output of Chinese chips has increased to 1billion, which will make it more difficult for foreign chips
Apple's self-developed baseband chip failed again, which shows Huawei Hisilicon's technological leadership