Given two strings
s1
ands2
, returntrue
ifs2
contains a permutation ofs1
, orfalse
otherwise.In other words, return
true
if one ofs1
's permutations is the substring ofs2
.
from collections import Counter
class Solution:
def checkInclusion(self, s1, s2):
# base case
if len(s1) > len(s2):
return False
c = Counter(s1)
# sliding window with length == len(s1)
for i in range(len(s2) - len(s1) + 1):
if Counter(s2[i:i+len(s1)]) == c:
return True
return False