Skip to content

Commit 13bf4d3

Browse files
committed
Time: 77 ms (72.81%), Space: 14 MB (28.54%) - LeetHub
1 parent 363a996 commit 13bf4d3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from collections import Counter
2+
class Solution:
3+
def checkInclusion(self, s1: str, s2: str) -> bool:
4+
c=Counter(s1)
5+
l=0
6+
r=0
7+
while(r<len(s2)):
8+
if(s2[r] in c and c[s2[r]]):
9+
c[s2[r]]-=1
10+
r+=1
11+
elif(s2[r] in c):
12+
if(r-l==len(s1)):
13+
return True
14+
else:
15+
while(s2[l]!=s2[r]):
16+
c[s2[l]]+=1
17+
l+=1
18+
l+=1
19+
r+=1
20+
else:
21+
if(r-l==len(s1)):
22+
return True
23+
else:
24+
r+=1
25+
while(l<r and l<len(s2)):
26+
if(s2[l] in c):
27+
c[s2[l]]+=1
28+
l+=1
29+
if(r-l==len(s1)):
30+
return True
31+
32+
return False
33+
34+
35+
36+

0 commit comments

Comments
 (0)