2
def isScramble(self, s1, s2):10
if len(s1) != len(s2):13
# Check both strings have same count of letters14
count1 = collections.defaultdict(int)15
count2 = collections.defaultdict(int)16
for c1, c2 in zip(s1, s2):22
# Iterate through letters and check if it results in a partition of23
# string 1 where the collection of letters are the same24
# on the left (non-swapped) or right (swapped) sides of string 225
# Then we recursively check these partitioned strings to see if they are scrambled26
lcount1 = collections.defaultdict(int) # s1 count from left27
lcount2 = collections.defaultdict(int) # s2 count from left28
rcount2 = collections.defaultdict(int) # s2 count from right29
for i in xrange(len(s1) - 1):32
rcount2[s2[len(s1) - 1 - i]] += 133
if lcount1 == lcount2: # Left sides of both strings have same letters34
if self.isScramble(s1[: i + 1], s2[: i + 1]) and self.isScramble(35
s1[i + 1 :], s2[i + 1 :]40
): # Left side of s1 has same letters as right side of s241
if self.isScramble(s1[: i + 1], s2[-(i + 1) :]) and self.isScramble(42
s1[i + 1 :], s2[: -(i + 1)]