목차
https://leetcode.com/problems/permutations-ii/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
전체 코드
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
answer = []
def dfs(prefix, num):
if not num:
if prefix not in answer:
answer.append(prefix)
return
for i, n in enumerate(num):
dfs(prefix + [n], num[:i] + num[i+1:])
dfs([], nums)
return answer
'Coding Test > Python' 카테고리의 다른 글
[백준/BFS&DFS] 1926번: 그림 (python, 실버 1) (0) | 2024.03.11 |
---|---|
[백준/union-find] 1717번: 집합의 표현(골드5, python) (0) | 2024.02.15 |
[LeetCode] 46. Permutations (Medium, Python) (0) | 2024.02.14 |
[백준/구현] 20057번: 마법사 상어와 토네이도(골드3, python) (1) | 2024.02.09 |
[프로그래머스/GREEDY] 구명보트 (level2, python) (0) | 2024.02.04 |
https://leetcode.com/problems/permutations-ii/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
전체 코드
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
answer = []
def dfs(prefix, num):
if not num:
if prefix not in answer:
answer.append(prefix)
return
for i, n in enumerate(num):
dfs(prefix + [n], num[:i] + num[i+1:])
dfs([], nums)
return answer
'Coding Test > Python' 카테고리의 다른 글
[백준/BFS&DFS] 1926번: 그림 (python, 실버 1) (0) | 2024.03.11 |
---|---|
[백준/union-find] 1717번: 집합의 표현(골드5, python) (0) | 2024.02.15 |
[LeetCode] 46. Permutations (Medium, Python) (0) | 2024.02.14 |
[백준/구현] 20057번: 마법사 상어와 토네이도(골드3, python) (1) | 2024.02.09 |
[프로그래머스/GREEDY] 구명보트 (level2, python) (0) | 2024.02.04 |