프로그래밍/LeetCode
[LeetCode][Python3] 46. Permutations
snoopybox
2018. 11. 12. 23:41
Problem :
https://leetcode.com/problems/permutations
My Solution :
class Solution:
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
def dfs(prefix, remain):
if not remain:
return ans.append(prefix[:])
for i in range(len(remain)):
prefix.append(remain[i])
dfs(prefix, remain[:i] + remain[i+1:])
prefix.pop()
ans = []
dfs([], nums)
return ans
Comment :
예전에 혼자 생각해봤던 문제가 그대로 나와서 그냥 그 방법대로 접근했다.