From dcdd53a678c3175faf6087c7611bd9d92e21c0e0 Mon Sep 17 00:00:00 2001 From: Emmanuel Valentin Date: Sun, 8 Jun 2025 22:37:47 -0600 Subject: [PATCH] Add permutations.py --- permutations.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 permutations.py 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