일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 30. Substring with Concatenation of All Words
- 파이썬
- 시바견
- Protocol
- concurrency
- 109. Convert Sorted List to Binary Search Tree
- iterator
- 315. Count of Smaller Numbers After Self
- 밴픽
- Python
- Python Code
- attribute
- Regular Expression
- 운영체제
- Convert Sorted List to Binary Search Tree
- 프로그래머스
- kaggle
- Generator
- Class
- 컴퓨터의 구조
- 715. Range Module
- data science
- DWG
- 43. Multiply Strings
- Substring with Concatenation of All Words
- LeetCode
- Python Implementation
- Decorator
- t1
- shiba
Archives
- Today
- Total
Scribbling
LeetCode: 90. Subsets II 본문
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
nums.sort()
self.ret = []
self.dfs(nums, [])
return self.ret
def dfs(self, nums, path):
self.ret.append(path)
prev = None
for i, num in enumerate(nums):
if num != prev:
prev = num
self.dfs(nums[i+1:], path+[num])
Lazy version:
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
nums.sort()
self.ret = []
for p in self.gen(nums, []):
self.ret.append(p)
return self.ret
def gen(self, nums, path):
yield path
prev = None
for i, num in enumerate(nums):
if num != prev:
prev = num
yield from self.gen(nums[i+1:], path+[num])
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 91. Decode Ways (0) | 2021.10.11 |
---|---|
LeetCode: 100. Same Tree (0) | 2021.10.11 |
LeetCode: 88. Merge Sorted Array (0) | 2021.10.09 |
LeetCode: 98. Validate Binary Search Tree (0) | 2021.10.09 |
LeetCode: 99. Recover Binary Search Tree (0) | 2021.10.08 |