- 문제 링크: https://leetcode.com/problems/subsets-ii/
- 난이도: Medium
2024.09.16 - [Online Judge/LeetCode] - [LeetCode][Python] 78. Subsets
위 문제와 동일한데, 각 조합이 중복된 원소를 포함할 수 있다
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
sz = len(nums)
res = set()
nums.sort()
def backtrack(cur: int, picked: List[int]):
if cur == sz:
res.add(tuple(picked))
return
backtrack(cur+1, picked)
backtrack(cur+1, picked + [nums[cur]])
backtrack(0, [])
return [list(x) for x in res]
반응형
'Online Judge > LeetCode' 카테고리의 다른 글
[LeetCode][Python] 543. Diameter of Binary Tree (0) | 2024.09.17 |
---|---|
[LeetCode][Python] 104. Maximum Depth of Binary Tree (0) | 2024.09.16 |
[LeetCode][Python] 78. Subsets (0) | 2024.09.16 |
[LeetCode][Python] 226. Invert Binary Tree (0) | 2024.09.16 |
[LeetCode][Python] 19. Remove Nth Node From End of List (0) | 2024.09.13 |