Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 1.52 KB

_46. Permutations.md

File metadata and controls

57 lines (41 loc) · 1.52 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 07, 2024

Last updated : July 01, 2024


Related Topics : Array, Backtracking

Acceptance Rate : 79.29 %


Solutions

Python

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