-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path46.py
33 lines (23 loc) · 802 Bytes
/
46.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import re
import collections
import itertools
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
if not nums:
return []
def dfs(elements):
if len(elements) == 0:
result.append(prev_elements[:])
for e in elements:
next_elements = elements[:]
next_elements.remove(e)
prev_elements.append(e)
dfs(next_elements)
prev_elements.pop()
result = []
prev_elements = []
dfs(nums)
return result
class Solution2:
def permute(self, nums: List[int]) -> List[List[int]]:
return list(itertools.permutations(nums))