일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 109. Convert Sorted List to Binary Search Tree
- Regular Expression
- 43. Multiply Strings
- data science
- shiba
- 밴픽
- LeetCode
- DWG
- concurrency
- 715. Range Module
- 컴퓨터의 구조
- kaggle
- 프로그래머스
- 시바견
- Python
- Convert Sorted List to Binary Search Tree
- Substring with Concatenation of All Words
- 파이썬
- t1
- 315. Count of Smaller Numbers After Self
- 운영체제
- Python Implementation
- Decorator
- iterator
- attribute
- Python Code
- Protocol
- Class
- Generator
- 30. Substring with Concatenation of All Words
Archives
- Today
- Total
Scribbling
LeetCode: 40. Combination Sum II 본문
class Solution:
def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
candidates.sort()
self.ret = []
self.dfs(candidates, target, [])
return self.ret
def dfs(self, candidates, target, path):
if target < 0:
return
if target == 0:
self.ret.append(path)
return
prev = None
for i, candidate in enumerate(candidates):
if candidate != prev:
prev = candidate
self.dfs(candidates[i+1:], target-candidate, path+[candidate])
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 47. Permutations II (0) | 2021.09.07 |
---|---|
LeetCode: 46. Permutations (0) | 2021.09.07 |
37. Sudoku Solver (0) | 2021.09.06 |
36. Valid Sudoku (0) | 2021.09.06 |
44. Wildcard Matching (0) | 2021.09.06 |