当前位置:网站首页>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
边栏推荐
- Im instant messaging develops a message delivery scheme for 10000 people
- 模板引擎Velocity 基础
- Sqlserver query: when a.id is the same as b.id, and the A.P corresponding to a.id cannot be found in the B.P corresponding to b.id, the a.id and A.P will be displayed
- 红队第10篇:coldfusion反序列化过waf改exp拿靶标的艰难过程
- Flux d'entrées / sorties et opérations de fichiers en langage C
- SystemVerilog-结构体(二)
- sql刷题627. 变更性别
- Advantages, values and risks of chain games compared with traditional games
- 【Hot100】19. Delete the penultimate node of the linked list
- Rhcsa Road
猜你喜欢

数据库系统原理与应用教程(003)—— MySQL 安装与配置:手工配置 MySQL(windows 环境)
![[live broadcast appointment] database obcp certification comprehensive upgrade open class](/img/50/83a533f4e8a60f90e03b991385c08d.jpg)
[live broadcast appointment] database obcp certification comprehensive upgrade open class

怎麼用MySQL語言進行行列裝置?

How to solve the keyboard key failure of notebook computer

广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果

PR basic clip operation / video export operation

How long will it take to achieve digital immortality? Metacosmic holographic human avatar 8i

C語言輸入/輸出流和文件操作

Im instant messaging develops a message delivery scheme for 10000 people

Is the programmer's career really short?
随机推荐
[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
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
巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
How to solve the problem that the battery icon of notebook computer does not display
你还在用收费的文档管理工具?我这有更牛逼的选择!完全免费
【Hot100】20. Valid parentheses
怎麼用MySQL語言進行行列裝置?
How long will it take to achieve digital immortality? Metacosmic holographic human avatar 8i
How to maintain the laptop battery
广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果
程序员职业生涯真的很短吗?
How to restore the system of Sony laptop
UML tourism management system "suggestions collection"
制造业数字化转型究竟是什么
Leetcode 77 combination -- backtracking method
Kali install Nessus
Stonedb is building blocks for domestic databases, and the integrated real-time HTAP database based on MySQL is officially open source!
Zabbix2.2监控之系统及应用日志监控报警
VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
vim用户自动命令示例