leetcode 46-> Permutations
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