Simple 95% Python recursion code

  • 0

    Below are my Python recursion code. No complicated function/module is used. Hope you enjoy it! Any comments are welcomed!


    class Solution(object):
    def permute(self, nums):

        rlist, i = [], len(nums)
        if i == 0 or i == 1:
            rlist = [nums]
            temp = self.permute(nums[0:i-1])
            for j in range(len(temp)):
                for k in range(len(temp[j]) + 1):
                    rlist.append(temp[j][0:k] + [nums[i-1]] + temp[j][k:len(temp[j])])
        return rlist


Log in to reply

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