题目描述
给出一组数字,输出全排列的结果
例子:
Input: [1,2,3]
Output:
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2...对于一个数组[a1,a2,a3],那么它的全排列为:
Permute([a1,a2,a3])=[取出的某一个数]+Permute([a1,a2,a3]-取出的某一个数)
如果我们要用1,2,3进行排列...,我们可以先抽出一个元素,比如我们现在抽出1,那么我们下面要做的事就是使用2,3两个元素构造排列
代码实现
class Solution(object):
def permute(self, nums...):
helper(res,l+[r[i]],r[:i]+r[i+1:],n+1,max)
helper(res,[],nums,0,len(nums))...Permutations-全排列|回溯|递归|非递归
leetcode题解(递归和回溯法)