Skip to content

Commit dd6c1c0

Browse files
committed
feat: find-all-anagrams-in-a-string
1 parent 8ce7560 commit dd6c1c0

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

str.find-all-anagrams-in-a-string.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,15 @@ def findAnagrams(self, s: str, p: str) -> List[int]:
4242
# 窗口向右移
4343
left += 1
4444
right += 1
45-
4645
return res
4746

4847
def findAnagramsByForce(self, s: str, p: str) -> List[int]:
49-
# 通过滑动窗口解决问题
5048
res = []
5149
p_str = ''.join(sorted(p))
52-
win = len(p)
53-
l = len(s)
50+
window, length = len(p), len(s)
5451
i = 0
55-
while i <= l - win:
56-
tmp = s[i:i+win]
52+
while i <= length - window:
53+
tmp = s[i:i+window]
5754
if ''.join(sorted(tmp)) == p_str:
5855
res.append(i)
5956

0 commit comments

Comments
 (0)