@@ -0,0 +1,905 @@
+#!/usr/bin/env python%0A%0Aclass Solution:%0A    def __init__(self):%0A        self.poss = set()%0A        self.imposs = set()%0A    # @return a boolean%0A    def isScramble(self, s1, s2):%0A        print %22input %25s %25s%22 %25 (s1, s2)%0A        if s1 == s2:%0A            return True%0A        if (s1, s2) in self.poss:%0A            return True%0A        if (s1, s2) in self.imposs:%0A            return False%0A        assert len(s1) == len(s2)%0A        for i in range(1, len(s1)):%0A            if self.isScramble(s1%5B:i%5D, s2%5B:i%5D) and self.isScramble(s1%5Bi:%5D, s2%5Bi:%5D) or self.isScramble(s1%5B:i%5D, s2%5B-i:%5D) and self.isScramble(s1%5Bi:%5D, s2%5B:len(s1)-i%5D):%0A                self.poss.add((s1,s2))%0A                return True%0A        self.imposs.add((s1,s2))%0A        return False%0A%0Adef test(a, b):%0A    sol = Solution()%0A    print %22input: '%25s' '%25s'%22 %25 (a, b)%0A    print %22result %25s%22 %25 (sol.isScramble(a, b))%0A%0Aif __name__ == %22__main__%22:%0A    test(%22ab%22, %22ba%22)%0A

add solution for scramble string