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

0046 - Permutations #301

@Ayushmanglani

Description

@Ayushmanglani

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions