当前位置:网站首页>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
边栏推荐
- Virtual serial port simulator and serial port debugging assistant tutorial "suggestions collection"
- Chinese diosgenin market forecast and investment strategy report (2022 Edition)
- [nodemon] app crashed - waiting for file changes before starting...解决方法
- Advantages, values and risks of chain games compared with traditional games
- 【Hot100】17. Letter combination of telephone number
- 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
- 软件工程导论——第六章——详细设计
- 剑指 Offer II 015. 字符串中的所有变位词
- Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
- 模板引擎Velocity 基礎
猜你喜欢

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
![[observation] where is the consulting going in the digital age? Thoughts and actions of softcom consulting](/img/82/3bb382893682a30e8af130365ec4ef.jpg)
[observation] where is the consulting going in the digital age? Thoughts and actions of softcom consulting

数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)

【SQL语句】请问这边为什么select出了两个上海,查询出了不同的count我想让他变成一个上海,count只显示一个总和

Are you still using charged document management tools? I have a better choice! Completely free

Flux d'entrées / sorties et opérations de fichiers en langage C

软件工程导论——第六章——详细设计

Problems encountered in IM instant messaging development to maintain heartbeat

Leetcode 77 combination -- backtracking method

Endeavouros mobile hard disk installation
随机推荐
广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果
Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
瑞典公布决定排除华为5G设备,但是华为已成功找到新出路
Zabbix2.2监控之系统及应用日志监控报警
數據庫系統原理與應用教程(006)—— 編譯安裝 MySQL5.7(Linux 環境)
Go language source level debugger delve
sql刷题586. 订单最多的客户
数据库系统原理与应用教程(005)—— yum 离线安装 MySQL5.7(Linux 环境)
How to cancel automatic search and install device drivers for laptops
Red team Chapter 8: blind guess the difficult utilization process of the package to upload vulnerabilities
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
Origin2018安装与使用(整理中)
Germany if was crowned with many awards. How strong is this pair of headphones? In depth evaluation of yinpo GTW 270 hybrid
Leetcode 77 combination -- backtracking method
苹果自研基带芯片再次失败,说明了华为海思的技术领先性
China's intelligent transportation construction from the perspective of "one hour life circle" in Dawan District
sql刷题627. 变更性别
模板引擎Velocity 基礎
[daily question] 1175 Prime permutation
Rhcsa Road