The Way of Permutations

  • 0

    Not sure if this is acceptable,since permuting long strings may not work(Memory Limit/Time Limit), but this is one of the ways to find whether the given string one of it's permutations.Can also be used to generate power-set for a given string of length n

    class Solution(object):
        def isScramble(self, s1, s2):
     #assuming strings passed are of equal length, else corner case
            e = []
            for a in itertools.permutations(s1,len(s1)):
            if s2 in e:
                return True
                return False

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.