-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC46.py
More file actions
27 lines (23 loc) · 707 Bytes
/
LC46.py
File metadata and controls
27 lines (23 loc) · 707 Bytes
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
class Solution(object):
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
if not nums:
return []
ans = []
def helper(path,nums,vis):
if len(path) == len(nums):
ans.append([i for i in path])
return
for i in range(len(nums)):
if i not in vis:
vis.add(i)
path.append(nums[i])
helper(path,nums,vis)
vis.remove(i)
path.pop()
vis = set()
helper([],nums,vis)
return ans