当前位置:网站首页>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
边栏推荐
- 红队第8篇:盲猜包体对上传漏洞的艰难利用过程
- StoneDB 为国产数据库添砖加瓦,基于 MySQL 的一体化实时 HTAP 数据库正式开源!
- 瑞典公布决定排除华为5G设备,但是华为已成功找到新出路
- Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
- 为国产数据库添砖加瓦,StoneDB 一体化实时 HTAP 数据库正式开源!
- 用手机在同花顺上开户靠谱吗?这样有没有什么安全隐患
- Is the securities account given by the head teacher of goucai school safe? Can I open an account?
- How to use phpipam to manage IP addresses and subnets
- Is it reliable to open an account on flush with mobile phones? Is there any potential safety hazard
- Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
猜你喜欢
[live broadcast appointment] database obcp certification comprehensive upgrade open class
VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
Rhcsa Road
Motion capture system for apple picking robot
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
Tutorial on principles and applications of database system (004) -- MySQL installation and configuration: resetting MySQL login password (Windows Environment)
Tutorial on principles and applications of database system (006) -- compiling and installing MySQL 5.7 (Linux Environment)
VMware 虚拟机启动时出现故障:VMware Workstation 与 Hyper-v 不兼容...
Analysis of PostgreSQL storage structure
Tutorial on the principle and application of database system (002) -- MySQL installation and configuration: MySQL software uninstallation (Windows Environment)
随机推荐
虚拟串口模拟器和串口调试助手使用教程「建议收藏」
How to restore the system of Sony laptop
Installation and use of sqoop
Zabbix2.2 monitoring system and application log monitoring alarm
Buuctf gold III
免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
PR basic clip operation / video export operation
怎么用MySQL语言进行行列装置?
Rhcsa Road
VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
瑞典公布决定排除华为5G设备,但是华为已成功找到新出路
模板引擎Velocity 基础
程序员职业生涯真的很短吗?
sql刷题627. 变更性别
[JetsonNano] [教程] [入门系列] [三] 搭建TensorFlow环境
Comprehensively view the value of enterprise digital transformation
How to use MySQL language for row and column devices?
What are the differences between PHP and DW
C語言輸入/輸出流和文件操作