일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 43. Multiply Strings
- Python Implementation
- Substring with Concatenation of All Words
- 프로그래머스
- Python Code
- iterator
- DWG
- 운영체제
- Class
- 30. Substring with Concatenation of All Words
- shiba
- t1
- 109. Convert Sorted List to Binary Search Tree
- 715. Range Module
- data science
- Python
- 밴픽
- 시바견
- 파이썬
- Decorator
- kaggle
- concurrency
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- Protocol
- 컴퓨터의 구조
- LeetCode
- Generator
- attribute
- Regular Expression
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 |