Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/10/05 10:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串946/1548 (看更多)
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
文章代碼(AID): #1d0A5ycN (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1d0A5ycN (Marginalman)