-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ46.py
More file actions
27 lines (19 loc) · 743 Bytes
/
Q46.py
File metadata and controls
27 lines (19 loc) · 743 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
from typing import List
from itertools import permutations
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
if len(nums)==1:
return [nums]
resultList = []
def permuteHelper(result,remaining):
if len(remaining)==1:
resultList.append(result+[remaining[0]])
return
else:
for i in range(len(remaining)):
permuteHelper(result+[remaining[i]],remaining[0:i]+remaining[i+1:])
for i in range(len(nums)):
permuteHelper([nums[i]],nums[0:i]+nums[i+1:])
return resultList
if __name__ == '__main__':
print(len(Solution().permute([1])))