MediumRating 1584
567. Permutation in String
hash-tabletwo-pointersstringsliding-window
解題說明
C++ 解法
複雜度分析
虛擬碼
1. If len(s1) > len(s2): return false 2. Build count1[26] for s1, count2[26] for first window of s2 (size = len(s1)) 3. Count initial matches = number of indices i where count1[i] == count2[i] 4. Set l = 0 5. For r from len(s1) to len(s2) - 1: a. If matches == 26: return true b. Add s2[r] to window: increment count2[s2[r]], update matches c. Remove s2[l] from window: decrement count2[s2[l]], update matches d. l++ 6. Return matches == 26