46. Permutations
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 07, 2024
Last updated : July 01, 2024
Related Topics : Array, Backtracking
Acceptance Rate : 79.75 %
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
return itertools.permutations(nums)
# Since using itertools defeats the purpose of this quesiton lol
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
self.outs = []
def helper(current: List[int], remainingNums: set()) -> None :
if not remainingNums :
self.outs.append(current.copy())
return
nextRemainingNums = remainingNums.copy()
for i in remainingNums :
current.append(i)
nextRemainingNums.remove(i)
helper(current, nextRemainingNums)
nextRemainingNums.add(current.pop())
helper([], set(nums))
return self.outs