Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def generate(self, current, pos, nums, used, combinations):
- if pos == len(nums):
- combinations.append(current)
- return
- for i in range(len(nums)):
- if not used[i]:
- used[i] = True
- current = current[0:pos]
- current.append(nums[i])
- self.generate(current, pos + 1, nums, used, combinations)
- used[i] = False
- if pos == 0:
- return combinations
- def unique(self, l:list) -> list:
- unique_list = []
- for x in l:
- if x not in unique_list:
- unique_list.append(x)
- return unique_list
- def permutations(self, nums: list) -> list:
- used = [False for num in nums]
- return self.unique(self.generate([], 0, nums, used, []))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement