Leetcode - 46. Permutations
Coding Test

Leetcode - 46. Permutations

일시불

문제

풀이

class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        def get_perm(nums_):
            if len(nums_) == 1:
                return [nums_]

            res = []
            for i in range(len(nums_)):

                perms = get_perm(
                    [nums_[j] for j in range(len(nums_)) if j != i]
                )
                for perm in perms:
                    res.append([nums_[i]] + perm)

            return res

        return get_perm(nums)

전형적인 DFS 문제다. 왜 난이도가 medium인지 모르겠다..