forked from SocialfiPanda/Leetcode-Py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutations.py
More file actions
23 lines (21 loc) · 764 Bytes
/
Permutations.py
File metadata and controls
23 lines (21 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def permute(self, nums):
solutions = [[]]
for num in nums:
next = []
for solution in solutions:
for i in range(len(solution) + 1):
next.append(solution[:i] + [num] + solution[i:])
solutions = next
return solutions
# Recursive Solution
# def permute(self, nums):
# res = []
# self.permuteRecur(res, [], nums)
# return res
# def permuteRecur(self, res, current, nums):
# if len(nums) == 0:
# res.append(current)
# return
# for i in range(len(current) + 1):
# self.permuteRecur(res, current[:i] + [nums[0]] + current[i:], nums[1:])