class Solution(object):
def isScramble(self, s1, s2):
if sorted(s1) != sorted(s2): return False
if len(s1)<4: return True
"""
:type s1: str
:type s2: str
:rtype: bool
"""
for i in range(1, len(s1)):
if self.isScramble(s1[i:], s2[i:]) and self.isScramble(s1[:i], s2[:i]) :
return True
if self.isScramble(s1[i:], s2[:-i]) and self.isScramble(s1[:i], s2[-i:]) :
return True
return False