LeetCode 567. [Python] Permutation in String
原题链接
中等
作者:
徐辰潇
,
2020-10-01 23:33:08
,
所有人可见
,
阅读 639
class Solution:
def checkInclusion(self, s1: str, s2: str) -> bool:
#TC: O(len(s2))
#SC: O(1)
#Using two dicts as metrics to evaluate whether s1 and substring of s2 are permutating of each other
Dict1 = [0]*26
for char in s1:
Dict1[ord(char) - ord('a')] += 1
TotalLen = len(s1)
Dict2 = [0]*26
for i, char in enumerate(s2):
Dict2[ord(char) - ord('a')] += 1
if i >= TotalLen:
Dict2[ord(s2[i - TotalLen]) - ord('a')] -= 1
if Dict2 == Dict1:
return True
return False