-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path46.py
More file actions
21 lines (20 loc) · 652 Bytes
/
Copy path46.py
File metadata and controls
21 lines (20 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
def BackTrack(m, per: list):
if m == n:
permutation.append(per)
return per
for i in range(n):
if not visited[i]:
per.append(nums[i])
visited[i] = True
per = BackTrack(m + 1, per)
per = per[:-1]
visited[i] = False
return per
n = len(nums)
visited = [False for _ in range(n)]
per = []
permutation = []
BackTrack(0, [])
return permutation