Why does my recursion exceed the maximum recursion depth limit?

  • 0
    class Solution(object):
        def permute(self, nums):
        :type nums: List[int]
        :rtype: List[List[int]]
        if nums == None or len(nums) <= 1:
            return [nums]
        res_lst = []
        res = []
        self.permuteHelper(res_lst, nums, res)
        return res_lst
    def permuteHelper(self, res_lst, nums, res):
        if len(res) == len(nums):
        for n in nums:
            if n not in res:
                self.permuteHelper(res_lst, nums,res+[n])
                res = res[:-1] #Prune back one node

Log in to reply

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