This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Description
Description of the Problem
Given a collection of distinct integers, return all possible permutations.
Code
class Solution:
def permutations(self, nums: List[int]):
if not nums:
yield []
for num in nums:
remaining = list(nums)
remaining.remove(num)
for perm in self.permutations(remaining):
yield [num] + list(perm)
def permute(self, nums: List[int]) -> List[List[int]]:
return list(self.permutations(nums))
Link To The LeetCode Problem
LeetCode