-
[LeetCode] 438. Find All Anagrams in a String알고리즘 2022. 6. 21. 21:43
from collections import Counter class Solution: def findAnagrams(self, s: str, p: str) -> List[int]: C = Counter(p) length = len(p) n = len(s) left = 0 right = length - 1 Temp = Counter(s[left: right + 1]) ret = [] while (right < n): if (Temp == C): ret.append(left) if (right == n - 1): return ret Temp[s[left]] -= 1 left += 1 right += 1 Temp[s[right]] += 1
'알고리즘' 카테고리의 다른 글
[LeetCode] 1354. Construct Target Array With Multiple Sums (0) 2022.06.24 [LeetCode] 90. Subsets II (0) 2022.06.22 Manacher's Algorithm [가장 긴 펠렌드롬 찾기] (0) 2022.06.20 [LeetCode] DP / Unique-paths (0) 2022.06.14 [LeetCode] HashTable/ 73. Set Matrix Zeroes (0) 2022.06.12