Skip to content

Commit bf571ce

Browse files
committed
新增字母异位词查找算法实现
1 parent 500cee3 commit bf571ce

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • leetcode/Study Plan/438. 找到字符串中所有字母异位词
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-03-12 00:57:22
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-03-12 00:57:24
6+
'''
7+
class Solution:
8+
def findAnagrams(self, s: str, p: str) -> List[int]:
9+
cnt = Counter(p)
10+
ans = []
11+
12+
left = 0
13+
for right,c in enumerate(s):
14+
cnt[c] -= 1
15+
while cnt[c] < 0:
16+
cnt[s[left]] += 1
17+
left += 1
18+
if right - left + 1 == len(p):
19+
ans.append(left)
20+
21+
return ans

0 commit comments

Comments
 (0)