Given a collection of distinct integers, return all possible permutations.

class Solution(object):
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        def backtracking(nums,res,cur):
            if len(nums) == 1:
                cur.append(nums[0])
                res.append(cur)
            else:
                for i in range(len(nums)):
                    backtracking(nums[:i]+nums[i+1:],res,cur+[nums[i]])
        res = []
        backtracking(nums,res,[])
        return res

 

相关文章:

  • 2021-10-19
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-15
  • 2021-12-19
  • 2022-02-09
  • 2021-09-10
  • 2021-09-10
  • 2021-09-18
相关资源
相似解决方案