-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathanswer.py
More file actions
25 lines (20 loc) · 735 Bytes
/
answer.py
File metadata and controls
25 lines (20 loc) · 735 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
#!/usr/bin/python
#------------------------------------------------------------------------------
class Solution:
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
result = []
self.helper(nums, [], result)
return result
def helper(self, nums, curr, result):
if not nums:
result.append(curr)
else:
for i in range(len(nums)):
# This removes the element from nums and puts it in curr for the next call
self.helper(nums[:i]+nums[i+1:], curr+[nums[i]], result)
#------------------------------------------------------------------------------
#Testing