We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4e98bb9 commit d459021Copy full SHA for d459021
permutations.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def permute(self, nums: List[int]) -> List[List[int]]:
3
+ permutations = self.search([], nums)
4
+ numlen = len(nums)
5
+ permutations = [permutations[i * numlen:(i + 1) * numlen] for i in range((len(permutations) + numlen - 1) // numlen )] #oneliner splitting list into chunks
6
+ return permutations
7
+
8
+ def search(self, current: List[int], possible: List[int]) -> List[int]:
9
+ final = []
10
+ if possible == []:
11
+ return []
12
+ elif len(possible) == 1:
13
+ return current + [possible[0]]
14
+ for num in possible:
15
+ final.extend(self.search(current + [num], [p for p in possible if p != num]))
16
+ return final
0 commit comments