From bb1d6afba1e2c4f3a3c26df11ef3c90547e92af4 Mon Sep 17 00:00:00 2001 From: Calm-23 Date: Mon, 5 Oct 2020 11:22:17 +0530 Subject: [PATCH 1/2] 0567_Permutations_in_String.py added --- LeetCode/0567_Permutation_in_String.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LeetCode/0567_Permutation_in_String.py diff --git a/LeetCode/0567_Permutation_in_String.py b/LeetCode/0567_Permutation_in_String.py new file mode 100644 index 0000000..c8c03fb --- /dev/null +++ b/LeetCode/0567_Permutation_in_String.py @@ -0,0 +1,12 @@ +#Sliding Window Approach +from collections import Counter +class Solution: + def checkInclusion(self, s1, s2): + d1, d2 = Counter(s1), Counter(s2[:len(s1)]) + for start in range(len(s1), len(s2)): + if d1 == d2: return True + d2[s2[start]] += 1 + d2[s2[start-len(s1)]] -= 1 + if d2[s2[start-len(s1)]] == 0: + del d2[s2[start-len(s1)]] + return d1 == d2 \ No newline at end of file From e021362ef8199e0b4b164581a5403042225a9051 Mon Sep 17 00:00:00 2001 From: Calm-23 Date: Mon, 5 Oct 2020 11:24:44 +0530 Subject: [PATCH 2/2] 0567_Permutations_in_String.py added --- ...67_Permutation_in_String.py => 0567_Permutations_in_String.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LeetCode/{0567_Permutation_in_String.py => 0567_Permutations_in_String.py} (100%) diff --git a/LeetCode/0567_Permutation_in_String.py b/LeetCode/0567_Permutations_in_String.py similarity index 100% rename from LeetCode/0567_Permutation_in_String.py rename to LeetCode/0567_Permutations_in_String.py