None recursive python code, accepted

  • 0
     class Solution:
            # @param num, a list of integer
            # @return a list of lists of integers
            def permute(self, num):
                result = [[]]
                permutations = []
                for i in num:
                    if result == [[]]:
                        result = [[i]]
                    else :
                        for j in result :
                            for k in range(0,len(j)+1) :
                                temp = j[:]
                        result = permutations[:]
                        permutations = []
                return result

  • 0

    Good to know this different way. Thanks!

    By the way, it is a little surprise (to me) that this non-recursive solution is not really faster than recursive solution. I think those intensive list mutation is also expensive.

Log in to reply

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