看板 Marginalman
567. Permutation in String ## 思路 用sliding window 掃s2 檢查固定長度內的char數量是否跟s1相同 ## Code ```python class Solution: def checkInclusion(self, s1: str, s2: str) -> bool: if len(s1) > len(s2): return False n = len(s1) target = Counter(s1) count = Counter() for idx, ch in enumerate(s2): count[ch] += 1 if idx >= n: count[s2[idx-n]] -= 1 if count == target: return True return False ``` -- https://i.imgur.com/kyBhy6o.jpeg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.178 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728094588.A.997.html