[LeetCode][Python3] 46. Permutations
2018. 11. 12. 23:41 |
프로그래밍/LeetCode
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 :
예전에 혼자 생각해봤던 문제가 그대로 나와서 그냥 그 방법대로 접근했다.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 62. Unique Paths (6) | 2018.11.15 |
---|---|
[LeetCode][Python3] 55. Jump Game (0) | 2018.11.15 |
[LeetCode][Python3] 49. Group Anagrams (0) | 2018.11.14 |
[LeetCode][Python3] 48. Rotate Image (0) | 2018.11.13 |
[LeetCode][Python3] 36. Valid Sudoku (0) | 2018.11.11 |
[LeetCode][Python3] 34. Find First and Last Position of Element in Sorted Array (0) | 2018.11.11 |
[LeetCode][Python3] 22. Generate Parentheses (0) | 2018.11.10 |
[LeetCode][Python3] 19. Remove Nth Node From End of List (0) | 2018.11.09 |
최근에 달린 댓글 최근에 달린 댓글