class Solution:
def checkInclusion(self, s1: str, s2: str) -> bool:
s1Dict = {}
for char in s1:
if char not in s1Dict:
s1Dict[char] = 1
else:
s1Dict[char] += 1
left = 0
compareDict = {}
for right in range((left + (len(s1) - 1)), len(s2)):
if s2[left] in s1:
compare = s2[left:right + 1] #makes a list of chars from left to right pointers
for char in compare:
if char not in compareDict:
compareDict[char] = 1
else:
compareDict[char] += 1
if compareDict == s1Dict:
return True
else:
compareDict.clear()
left += 1
continue
else:
left += 1
return False
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter