Skip to content

Commit 0f4dc5c

Browse files
Time: 47 ms (93.13%) | Memory: 16.5 MB (88.94%) - LeetSync
1 parent 502ae21 commit 0f4dc5c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def checkInclusion(self, s1: str, s2: str) -> bool:
3+
n, m = len(s1), len(s2)
4+
if n > m:
5+
return False
6+
d1 = {}
7+
for i in s1:
8+
d1[i] = d1.get(i, 0) + 1
9+
10+
d2 = {}
11+
for right in range(n-1):
12+
d2[s2[right]] = d2.get(s2[right], 0) + 1
13+
14+
left = 0
15+
for right in range(n-1, m):
16+
d2[s2[right]] = d2.get(s2[right], 0) + 1
17+
if d1 == d2:
18+
return True
19+
d2[s2[left]] -= 1
20+
if d2[s2[left]] == 0:
21+
del d2[s2[left]]
22+
left += 1
23+
24+
return False

0 commit comments

Comments
 (0)