---
# System prepended metadata

title: '#46 Permutations'
tags: [LeetCode, ' Top100']

---

---
title: "#46 Permutations"
tags: LeetCode, Top100
---
#46 Permutations
==

題目描述
--
Given an array `nums` of distinct integers, return all the possible permutations. You can return the answer in **any order**.

> Constraints:
 1 <= nums.length <= 6
 -10 <= nums[i] <= 10
 All the integers of nums are unique.

Example 1:
--
Input: [1,2,3]

Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]


解題思維
--
利用DFS遍歷，找出每一種可能。


DFS
--
```python=
class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        res = []

        def dfs(nums, path: List[int], point):
            if point == 0:
                res.append(path)
                return
            for i in range(point):
                dfs(nums[:i]+nums[i+1:], path+[nums[i]], point-1)
        dfs(nums, [], len(nums))
        return res
```