diff --git a/permutations.py b/permutations.py new file mode 100644 index 0000000..31bf30f --- /dev/null +++ b/permutations.py @@ -0,0 +1,17 @@ +class Solution: + def permute(self, nums: List[int]) -> List[List[int]]: + if len(nums) <= 1: + return [nums] + + permutations = [] + + for i in range(len(nums)): + element = nums[i] + remaining = nums[:i] + nums[i+1:] + + sub_permutations = self.permute(remaining) + + for perm in sub_permutations: + permutations.append([element] + perm) + + return permutations