The Way of Permutations


  • 0
    K

    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
            if(len(s1)!=len(s2)):
                return
            e = []
            for a in itertools.permutations(s1,len(s1)):
                e.append("".join(a))
            if s2 in e:
                return True
            else:
                return False
    

Log in to reply
 

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