본문 바로가기
알고리즘/소스코드

LEETCODE 46: PERMUTATIONS

by cjw.git 2021. 8. 5.

Link : https://leetcode.com/problems/permutations/


Python

더보기
1
2
3
4
5
6
7
8
9
10
11
12
class Solution:
    def DFS(self, extra, result, deapth):
        t_list = []
        if len(extra) == 0:
            return [result[:]]
        for idx, val in enumerate(extra):
            result[deapth] = val;
            t_list += self.DFS(extra[:idx] + extra[idx + 1:], result, deapth + 1)
        return t_list
 
    def permute(self, nums: list[int]) -> list[list[int]]:
        return self.DFS(nums, [None for _ in range(len(nums))], 0)
cs

FeedBack

  1.  

 

 

 

cjw.git@gmail.com

댓글